The final step is to add the data you want to show to your chart. This step requires you to write some code.
In most applications, the data will come from an ADO.NET DataSet, often with some transformations such as filtering, sorting, or summarizing. It is also possible to chart data from other sources, such as arrays or custom data structures. Regardless of where the data comes from, you can add it to the chart using methods provided by the ChartDataSeries class.
For example, the following C# code populates a chart using data from a DataTable:
private void Page_Load(object sender, EventArgs e)
{
// get dataset (from db or cache)
DataSet ds = GetDataSet();
// filter the data
DataView dv = new DataView(ds.Tables["Sales"]);
dv.RowFilter = "ProductSales >= 40000";
dv.Sort = "ProductSales";
// create an array of data points
PointF[] data = new PointF[dv.Count]
for (int i = 0; i < data.Length; i++)
{
float y = float.Parse(dv[i]["ProductSales"].ToString());
data[i] = new PointF(i, y);
}
// populate chart data points
ChartDataSeries series =
_c1webChart.ChartGroups[0].ChartData.SeriesList[0];
series.PointData.CopyDataIn(data);
}
For more details on how to add data to charts, see Entering and Modifying Chart Data.
Note: C1Chart and C1Chart3D are the WinForms control used by C1WebChart and C1WebChart3D, respectively, to generate the charts.
Send comments about this topic to ComponentOne. Copyright © ComponentOne LLC. All rights reserved. |