I have created some simple charts (of type FastLine) with MSChart and update them with live data, like below:
To do so, I bind an observable collection of a custom type to the chart like so:
// set chart data source
this._Chart.DataSource = value; //is of type ObservableCollection<SpectrumLevels>
//define x and y value members for each series
this._Chart.Series[0].XValueMember = "Index";
this._Chart.Series[1].XValueMember = "Index";
this._Chart.Series[0].YValueMembers = "Channel0Level";
this._Chart.Series[1].YValueMembers = "Channel1Level";
// bind data to chart
this._Chart.DataBind(); //lasts 1.5 seconds for 8000 points per series
At each refresh, the dataset completely changes, it is not a scrolling update!
With a profiler I have found that the DataBind()
call takes about 1.5 seconds. The other calls are negligible.
How can I make this faster?
- Should I use another type than ObservableCollection? An array probably?
- Should I use another form of data binding?
- Is there some tweak for the MSChart that I may have missed?
- Should I use a sparsed set of date, having one value per pixel only?
- Have I simply r开发者_开发百科eached the performance limit of MSCharts?
From the type of the application to keep it "fluent", we should have multiple refreshes per second.
Thanks for any hints!
EDIT: Solution as proposed by leppie:
this._Chart.Series[0].Points.Clear();
foreach (var item in value) //iterates over the list of custom objects
{
this._Chart.Series[0].Points.Add(new DataPoint
{
XValue = item.Index,
YValues = new double[] { item.Channel0Level.Value }
});
}
This now works more than twice as fast!
Use the other Bind methods, they are very fast.
I update about 15 series over 3 areas, with 300 points in every series, every second, and no real slow down.
精彩评论