RCHART .NET TUTORIAL, Chapter 10
Copyright 2003, J4L
Components (http://www.java4less.com)
Go bak to contents
RChart .NET windows Control
Adding
the ChartControl to your forms
The ChartControl allows you to displays chart in your windows applications.
You can use our test application source/ChartViewer.cs as a reference.You can
put the ChartControl in your panel or forms like this:
[c#]
void
InitializeForm() {
this.chartControl= new J4L.RChart.ChartControl();
this.SuspendLayout();
this.chartControl.Location = new System.Drawing.Point(0, 0);
this.chartControl.Name = "chart";
this.chartControl.Size = new System.Drawing.Size(500, 350);
this.chartControl.TabIndex = 0;
//
// add chartControl to the form
//
this.ClientSize = new System.Drawing.Size(500, 350);
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.chartControl});
this.Text = "Chart viewer";
this.ResumeLayout(false);
}
Creating
the chart
Once the ChartControl is in your panel or form, you must create the chart.
There are 3 ways to do this:
- Load chart from data file:
[c#]
ChartLoader cha=chartControl.getChartLoader();
cha.loadFromFile("dataFile.txt",true);
chartControl.buildChart();
this.Refresh(); // where "this" is your form
- Provide the parameters in your code:
[c#]
ChartLoader cha=panel.getChartLoader();
cha.clearParams();
cha.setParameter("TITLECHART","Sales 2002");
cha.setParameter("XLABEL","Month");
cha.setParameter("YLABEL","Million $");
.......
.......
cha.setParameter("BIG_TICK_INTERVALY","10");
cha.setParameter("XAXIS_LABELS","June|July|Aug.|Sept.|Oct.|Nov.|Dec.");
chartControl.buildChart();
this.Refresh(); // where "this" is your form
- Create the Chart object using the API:
[c#]
// data
double[] d1={1,1,3,3.5,5,4,2};
double[] d2={2,2,5,6,5.4,3.5,3.1};
// series LineDataSerie
data1= new LineDataSerie(doubleArrayToRValue(d1),new LineStyle(1,Color.Blue,LineStyle.LINE_NORMAL));
// plotter
LinePlotter3D plot=new LinePlotter3D();
......
.....
// create chart
Chart chart=new Chart(title,plot,XAxis,YAxis);
plot.border=new LineStyle(1,Color.Black,LineStyle.LINE_NORMAL);
plot.back=new FillStyle(Color.White);
chart.XLabel=XLabel;
chart.YLabel=YLabel;
chart.legend=l;
chart.addSerie(data2);
chart.addSerie(data1);
chartControl.setChart(chart);
this.Refresh(); // where "this" is your form