Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Filling graph with data via code (Read 4687 times)
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Filling graph with data via code
May 5th, 2009 at 8:28pm
Print Post  
Hi!

Im new in using Chart component.

Currently I would like to create two lines on line graph via code. I dont care about labels on X axis these are not important for me. I want to create those lines from 10 000 values. I have these values in array.

What should I to set? Which property? I have problems with setting YData and working with YData.Item. Is it right to work with array? Or collection is better?

Based on info from docs I need to set also values of X axis. But it is odd always to create collection with numbers from 1 to 10 000 (or another).

And what does ClearData method really do? In docs thers only "Clears any data from the chart."

I know, so many questions... but it looks like it is really simple, but I dont know to set proper values and properties. Pls give me instructions how to do that.

Thx

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Filling graph with data via code
Reply #1 - May 6th, 2009 at 9:41am
Print Post  
Hi,

This sample line chart shows two arrays, each with 10 000 random numbers, ranging from 0 to 100. The chart would not be very legible when all 10000 points are displayed on the screen, so it's set to scrollable:

//set the data
const int dataCount = 10000;
const int listCount = 2;

Random rand = new Random(10);
double[][]data = new double[listCount][];

for (int i = 0; i < listCount; i++)
{
     data[i] = new double[dataCount];

     for (int j = 0; j < dataCount; j++)
           data[i][j] = rand.Next(100);
}            
           

lineChart1.YData.Clear();
lineChart1.XData.Clear();
lineChart1.YData = data;

//appearance settings
lineChart1.ChartPens = new MindFusion.Drawing.PenCollection("n:0/#FF0CB00C/1/0/0//0/0/10/,n:0/#FFFF0000/0/0
/0//0/0/10/");
lineChart1.LineType = MindFusion.Charting.LineTypes.Line;            
this.lineChart1.ResizeType = MindFusion.Charting.WinForms.ResizeType.Scrollable;
           
//X-axis settings
this.lineChart1.XAxisSettings.AxisLength = 5000F;
this.lineChart1.XAxisSettings.LabelType = MindFusion.Charting.AxisLabelType.AutoScale;
         
//Y-axis settings
this.lineChart1.YAxisSettings.AxisDelta = 10;
this.lineChart1.YAxisSettings.MaxValue = 100;
this.lineChart1.YAxisSettings.MinValue = 0;

//update the chart with the new settings
lineChart1.UpdateChart();

ClearData() clears all numbers and labels that are set for any chart. In charts with axes these are XData, YData, Y2Data, XLabels, YLabels etc. In pie charts it will clear InnerLabels, OuterLabels, Data etc. LegendLabels are also emptied.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint