Jump to content
Software FX Community

Using the ListProvider in ChartFX for Visual Studio 2005


Recommended Posts

When it comes to pass data to the control, ChartFX provides the developer with several options.

Besides using the API to specify individual values, it is possible to bind the Chart to one of the supported Data providers.

While the use of Databases and text files is very straightforward, using ArrayLists to populate the charts frequently prompts inquiries from some ChartFX users.

To illustrate how to correctly use ArrayLists to populate the control, lets set up a chart from an array list with two arrays; one array will provide the Y coordinates and the second will specify the corresponding X coordinates for each point.

We start by creating the data arrays and the ArrayList:

int[] Yvalues = { 1000, 850, 1120, 900,1200};

int[] Xvalues = { 120, 500, 600, 750, 920 };

chartDataList = new ArrayList();



Then, we need to tell the chart that it has to treat the second field as Xvalues instead of as a second data series. To do this, we need to add the necessary FieldMap objects to the Fields collection of the Chart. This is where some users get stuck.
When working with DataBases, the dataset contains the actual name of each data column, thus referencing a specific field is done by simply passing the name of that field as the fist parameter of the Fieldmap object:

chart1.DataSourceSettings.Fields.Add(new FieldMap("Measure", FieldUsage.Value)); 

However, there is no header for each element in the ArrayList we just created. Therefore, we will need to use “FieldN” instead:

chart1.DataSourceSettings.Fields.Add(new FieldMap("Field1", FieldUsage.Value));

chart1.DataSourceSettings.Fields.Add(new FieldMap("Field2", FieldUsage.XValue)); 

We just told the chart to use the first array in the List as a Y values and the second array as Xvalues. Now, all we have left to do is Create the ListProvider object, populate it with the List array and bind it to the chart:

ChartFX.WinForms.DataProviders.ListProvider lstProvider = new ChartFX.WinForms.DataProviders.ListProvider(chartDataList);

Chart1.DataSourceSettings.DataSource = lstProvider;

This same logic can be used when setting IniValues (for Bar, Gantt or area charts).

Also, If you want to set Dates as X values it is simply a matter of defining the type of the array and passing the correct values:

dateInit = new DateTime(2001,12,02);

DateTime[] Xvalues = { dateInit, dateInit.AddYears(1), dateInit.AddYears(2) };

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

I'm having a problem with the ListProvider. I've loaded it with an arraylist which contains 7 series. I add it to the chart properly. However, I have to add the chart to the vs studio watch window and navigate to the Series property of the chart for my app to work, else the app crashes when I try to reference any series I passed to the chart via the ListProvider. Why is this happening?

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...