How to rebind a charts data source?


#1

Hi,

I have a simple timeseries chart as a detail view in a master detail pad layout, when an stock is selected in the master view I want to rebind the chart, with typically ten years of end of day data.

In my attempt I do:
chart.DataSource = myNewDataSource;
chart.ReloadData();
chart.Redraw();

Problem is that the x-axis (SChartDateTime) goes bananas, particular the x-axis lower value is  more than  100 years back in time. If I pan forever to a valid range I can also see that the old series sems also to still be around (although the legend only displays that last, and correct series).

Am I missing some API call before/after the rebind? 

When the chart is initially created and bound, everything looks as expected.

The series being exposed by my data source is a SChartStepLineChart.

The only work around I could do was to recreate the entire chart  and remove the old ine and add the new to current view, but this seems like a huge overkill as it bit slow creating a chart.

Regards
Lars


#2

Hi LarsKJ,

We’ve done a quick test on switching dataseries on a reload/redraw using a date-time axis and cannot seem to replicate this behaviour.

Is it possible that you’re returning both the old series and new series after the reload/redraw?

Sending us an example of this behaviour (a simple demo app, or your chart config/datasource/delegate code) to info@shinobicontrols is probably the easiest way for us to track down the cause of the problem.


#3

Hi,

Here are some code that is based on the supplied CandleStick demo, the rebind button in the top left corner just sets a new data source, actually an identical. A clue might be that if I comment the xaxis.DefaultRange - the problem seems to go away.

var xaxis = new SChartDateTimeAxis () {
				EnableGesturePanning = true,
				EnableGestureZooming = true,
				EnableMomentumPanning = true,
				EnableMomentumZooming = true,
			};
			xaxis.DefaultRange = new SChartDateRange(new DateTime(2011,1,1), new DateTime(2012,1,1));
			//xaxis.AddExcludedTimePeriod( new SChartTimePeriod(new DateTime(2009,1,3), SChartDateFrequency.CreateWithDay(2)));
			chart.XAxis = xaxis;

			chart.XAxis.Style.LineWidth = 1;
			var yAxis = new SChartNumberAxis () {
				EnableGesturePanning = false,
				EnableGestureZooming = false,

			};
			chart.YAxis = yAxis;

			chart.YAxis.Style.LineWidth = 1;
			//yAxis.VisibleRange



			// Add to the view
			View.AddSubview (chart);


			var ds = new CandlestickChartDataSource ();
			chart.DataSource = ds;


			UIButton b = new UIButton (UIButtonType.System);
			b.Frame = new RectangleF (10, 10, 100, 20);
			b.SetTitle ("Rebind", UIControlState.Normal);

			b.TouchUpInside += (object sender, EventArgs e) => {
				var ds1 = new CandlestickChartDataSource ();
				chart.DataSource = ds1;
				chart.ReloadData();
				chart.RedrawChart();
			};

			View.AddSubview (b);

#4

Hi rgrey,

Did the code snippet help in reproducting the problem?

Lars