Trying to create pie chart

702 Views Asked by At

I have variables populated throughout my program and on the last form I'm trying to display a pie chart that shows the portions of each expense in respect to the total expenses. The code I have right now is as follows:

  Sub Chart()
    Chart1.Series("Expenses").ChartType = SeriesChartType.Pie

    Chart1.Series("Expenses").Points.Add(GlobalVariables.cellphone / totalexpenses * 100)
    Chart1.Series("Expenses").Points.Add(GlobalVariables.carinsurance / totalexpenses * 100)
    Chart1.Series("Expenses").Points.Add(GlobalVariables.drappointments / totalexpenses * 100)
    Chart1.Series("Expenses").Points.Add(GlobalVariables.grocery / totalexpenses * 100)
    Chart1.Series("Expenses").Points.Add(GlobalVariables.healthinsurance / totalexpenses * 100)
    Chart1.Series("Expenses").Points.Add(GlobalVariables.medications / totalexpenses * 100)
    Chart1.Series("Expenses").Points.Add(GlobalVariables.misc / totalexpenses * 100)
    Chart1.Series("Expenses").Points.Add(GlobalVariables.rent / totalexpenses * 100)
    Chart1.Series("Expenses").Points.Add(GlobalVariables.therapysessions / totalexpenses * 100)
    Chart1.Series("Expenses").Points.Add(GlobalVariables.travel / totalexpenses * 100)


    'Chart1.Width = 700
    Chart1.Legends.Add("Expenses")
    Chart1.Legends("Expenses").LegendStyle = LegendStyle.Table

End Sub

When I run the program and include the call to the sub the chart does not show at all and the legend still only shows "Series1." What am I doing wrong? How can I make this work?

1

There are 1 best solutions below

0
On

By default the 1st series is 'Series1' and the pie chart is taking the blank data of this series. You need to delete it if you would use your own series. Add this code as the 1st line : Chart1.Series.clear