views:

28

answers:

2

So I'm trying to update dataPoints programmaticaly in a column chart but whenever I do this, the column chart displays empty columns where there IS a number greater than zero, and displays a zero otherwise. Now the code below works for a pie chart but for some reason it does not work for the bar chart.

    barChart.Series(0).Points.Item(0).YValues.SetValue(countInstSubs, 0)
    barChart.Series(0).Points.Item(1).YValues.SetValue(countPCLRetSubs, 0)
    barChart.Series(0).Points.Item(2).YValues.SetValue(countSYNRetSubs, 0)
    barChart.Series(0).Points.Item(3).YValues.SetValue(countPRESListSubs, 0)
    barChart.Series(0).Points.Item(4).YValues.SetValue(countUSInstSubs, 0)
    barChart.Refresh()

When I use the designer to populate some static values, the chart displays those values. But once I try to update them, I get a blank chart. I have also tried clearing the series altogether and rebuilding it each time I want to change the graph but this did not work either.

Has anyone seen this before?

+1  A: 

Turns out the problem was with the axis scaling. Once the values change, the axis doesn't automatically recalculate (bug in my opinion) so you have to do it manually.

    barChart.Series(0).Points.Item(0).SetValueY(countInstSubs)
    barChart.Series(0).Points.Item(1).SetValueY(countPCLRetSubs)
    barChart.Series(0).Points.Item(2).SetValueY(countSYNRetSubs)
    barChart.Series(0).Points.Item(3).SetValueY(countPRESListSubs)
    barChart.Series(0).Points.Item(4).SetValueY(countUSInstSubs)
    barChart.ChartAreas(0).RecalculateAxesScale()
    barChart.Refresh()

This fixes the problem.

BitFiddler
A: 

Good job on figuring out the solution. You should mark it as the answer.

You can also add points dynamically with this syntax:

barChart.Series(0).Points.AddY(countInstSubs);
barChart.Series(0).Points.AddY(countPCLRetSubs);
barChart.Series(0).Points.AddY(countSYNRetSubs);
barChart.Series(0).Points.AddY(countPRESListSubs);
barChart.Series(0).Points.AddY(countUSInstSubs);
JohnB
You can't mark your own post as 'the answer' until the next day (otherwise I would ;-)) If you want you can vote on my answer and I will mark it as correct tomorrow :-D I figured that AddY would internally allocate another datapoint and append it to the existing datapoints. This is not what I want. I want the number of datapoints to remain the same and just update their values.
BitFiddler