reloadData not working


#1

Chart is not asking any more information from the data source when I reloadData. Here are my logs:

asking number of series (returns 1)
asking for specific series (returns an SChartLineSeries)
asking number of points (returns 0)
did finish loading, redrawing chart...

(a short while later)

reloading chart... (480 items)

 After this last log, reloadData is called and I would expect it to go and ask the number of series and points again, but it doesn’t do anything. I’ve tried it in the foreground and background by setting the property, same results. I’ve set a breakpoint and validated the chart-object is valid, it’s visible and draws the axes fine, I’ve tried initially returning 0 instead of 1 for the number of series. What am I missing?


#2

Here is some further information. I added a manual reload button for testing:

- (IBAction)reloadData:(UIButton*)sender
{
	NSLog(@"manual: reloading chart... (%d items)", self.chartData.count);
	[self.chartView reloadData];
}

When I press the button hooked up to this method, nothing happens. None of the datasource methods get called.

I set a breakpoint on the reloadData line above, here’s the debug console, showing that the data-source is set correctly:

2013-09-06 12:33:16.216 xxxx[3558:c07] manual: reloading chart... (480 items)
(lldb) po self.chartView.datasource
$0 = 0x0f684ad0 <xxChartController: 0xf684ad0>
(lldb) po self
$1 = 0x0f684ad0 <xxChartController: 0xf684ad0>

What do I need to do to the chart in order to make it reload?


#3

Hi Jay,

The chart has two separate methods for invalidation, one is reloadData, the other is redrawChart. The two are separate in order to allow you to make changes to the visual appearance of the chart, then redraw it without the datasource being queried.

If you are making changes to your data, you need to call both methods. Try updating your method as follows:

- (IBAction)reloadData:(UIButton*)sender
{
	NSLog(@"manual: reloading chart... (%d items)", self.chartData.count);
	[self.chartView reloadData];
	[self.chartView redrawChart];
}

#4

My mistake - I misunderstood that to mean that you have to specifically tell the chart to redraw after the data is loaded, so I was calling redrawChart from sChartDidFinishLoadingData (which was of course never getting called either).