PeterBunde

New Member
Joined
Dec 7, 2016
Messages
45
Fellow sufferers!

I just want to make a pie chart from arrays holding the values. Please see my code below, which loads the array review_statae into memory.

I want to do something like below.

I did lots of googling, never found the right way to do it.

Code:
Public Function piechart_build(url As String)

[buids the pie chart with the categories START, ACCEPT, REJECT and assigns the relative weight. START is blue, Accept is green and REJECT is red]

End Function

Code that loads the array into memory:

Code:
Public Function reboot_review_statae()
Dim url_pointer As Integer
Dim onetotwenty As Integer
Dim status As String
Sheet_ ("Review (F1+F2)")
url_pointer = 1
While Value_(1, url_pointer * 4 - 1) <> ""
    review_statae.Add Value_(1, url_pointer * 4 - 1), CreateObject("Scripting.Dictionary")
    
    review_statae(Value_(1, url_pointer * 4 - 1)).Add "START", 0
    review_statae(Value_(1, url_pointer * 4 - 1)).Add "REJECT", 0
    review_statae(Value_(1, url_pointer * 4 - 1)).Add "ACCEPT", 0
    
    For onetotwenty = 1 To 20
        
        status = "NULL"
        
        If Value_(onetotwenty * 13 - 4, url_pointer * 4 - 1) = "<" Then status = "START"
        If Value_(onetotwenty * 13 - 3, url_pointer * 4 - 1) = "=" Then status = "REJECT"
        If Value_(onetotwenty * 13 - 2, url_pointer * 4 - 1) = "ü" Then status = "ACCEPT"
        
        If status <> "NULL" Then review_statae(Value_(1, url_pointer * 4 - 1))(status) = review_statae(Value_(1, url_pointer * 4 - 1))(status) + 1
        
        Next onetotwenty
    
        url_pointer = url_pointer + 1
    
Wend
End Function
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
This was my messy code, which cost me a day's work and still is ugly. I am really disapointed the documentation and resources on the Internet is so poor.

Code:
Private Function gogo()
Call arraytochart(10, 7, 6)
End Function
Sub arraytochart(start As Integer, REJECT As Integer, ACCEPT As Integer)
Dim counter As Integer
Dim x As ChartObject
       Dim pts As Points
         Dim pt As Point
         Dim statez As Series
With Application.ActiveSheet
Set x = .ChartObjects.Add(10, 20, 200, 200)
x.Chart.charttype = xlPie
x.Chart.SeriesCollection.NewSeries
x.Chart.SeriesCollection(1).values = Array(start, REJECT, ACCEPT)
x.Chart.SeriesCollection(1).Points(1).Format.Fill.ForeColor.RGB = RGB(0, 51, 251)
x.Chart.SeriesCollection(1).Points(2).Format.Fill.ForeColor.RGB = RGB(251, 0, 0)
x.Chart.SeriesCollection(1).Points(3).Format.Fill.ForeColor.RGB = RGB(0, 255, 0)
x.Chart.HasTitle = False
x.Chart.HasLegend = False
'x.Chart.ApplyDataLabels Type:=xlDataLabelsShowLabel
'x.Chart.ApplyDataLabels Type:=xlDataLabelsShowLabelAndPercent

x.Chart.ApplyDataLabels xlDataLabelsShowValue
Set statez = x.Chart.SeriesCollection(1)
'statez.HasDataLabels = True
Set pts = statez.Points
counter = 0
         For Each pt In pts
         counter = counter + 1
                If counter = 1 Then pt.DataLabel.Text = "Start" & ": " & start
                If counter = 2 Then pt.DataLabel.Text = "REJECT" & ": " & REJECT
                If counter = 3 Then pt.DataLabel.Text = "ACCEPT" & ": " & ACCEPT
                
             pt.DataLabel.Font.Bold = True
            ' pt.DataLabel.Position = xlLabelPositionAbove
         Next pt
Set shp = ActiveSheet.Shapes(x.Chart.Parent.Name)
    SetChartPosition (70)
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,958
Messages
6,127,937
Members
449,412
Latest member
sdescharme

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top