Very often the programmers face the problem of displaying data from several data sources in a chart. At this point, we should admit that setting ASP.net data sources for WebChartViewer does not seem the best idea, because of specific limitations of the control. That's why we believe the approach discussed in the following article would make the programmer's life easier.
To begin with, let's assume we have some data source that includes records of visitors hosted by a store during the working day. Those records consist of number of customers that entered or left the shop at a particular time period. When displaying the records from this data source in WebChartViewer we can see that some of the record values both in 'Customers_in" and 'Customers_out' fields are displayed as zeroes, thus implying that no vistors entered or left the shop at this time. Since this information looks redundant and usually unnecessary, it would be a nice idea to filter this data in a data source. To do this, the most reasonable approach would look like splitting the existing data source into several datasets based on a sorting value.
In order to make it work:
1) Create an auxiliary class that implements PerpetuumSoft IDataContext interface. This class would be required for passing several data sources to a chart. In our sample it is called ‘CustomContext’.
2) Set the context programmatically directly into the chart as displayed below:
3) In Charts Designer set the data sources for series by specifying ‘DataSet1’ and ‘DataSet2’ accordingly.
4) Enjoy the chart.
The sample Visual Studio project can be downloaded by the link below:http://perpetuumsoft.com/Support/downloads/samples/ChartMultipleDataSources.zip