Copyright 2003, J4L
Components (http://www.java4less.com)
Go bak to contents
We recommend you to create charts using the parameters however if you need it you can create charts using the api (see documentation in the api subdirectory of your installation).
The process is:
1. Import RChart assembly |
[C#] |
2. Create the title | [C#] Title title=new Title("Sales (thousands $)"); [VB.NET] dim mytitle as Title = new Title("Sales (thousands $)") |
3. Create the axis you need (depends on the chart) |
[C#] |
4. Create the legend | [C#] Legend l=new Legend(); l.addItem("Products",new FillStyle(Color.Blue)); l.addItem("Services",new FillStyle(Color.Green)); [VB.NET] dim l as Legend=new Legend() l.addItem("Products",new FillStyle(Color.Blue)) l.addItem("Services",new FillStyle(Color.Green)) |
5. Create the axis labels |
[C#] YLabel= new VAxisLabel("Brutto",Color.Black,new Font(new FontFamily("Arial"),14); dim YLabel as VAxisLabel= new VAxisLabel("Brutto",Color.Black,new Font(new FontFamily("Arial"),14))
|
6. create the plotter (or plotters if you combine lines and bars) | [C#] LinePlotter3D plot=new LinePlotter3D(); [VB.NET] dim plot as LinePlotter3D=new LinePlotter3D() |
7. create the chart and set properties (labels,legend) | [C#] Chart chart=new Chart(title,plot,XAxis,YAxis); chart.XLabel=XLabel; chart.YLabel=YLabel; chart.legend=l; [VB.NET] dim mychart as Chart=new Chart(mytitle,plot,XAxis,YAxis) mychart.XLabel=XLabel mychart.YLabel=YLabel mychart.legend=l |
8. create the data series | [C#] RValue[] d1={RValue(1),RValue(1),RValue(3),RValue(3.5),RValue(5),RValue(4),RValue(2)}; LineDataSerie data1= new LineDataSerie(d1,new LineStyle(1,Color.Blue,LineStyle.LINE_NORMAL)); [VB.NET] dim d1 as RValue()={RValue(1),RValue(1),RValue(3),RValue(3.5),RValue(5),RValue(4),RValue(2)} dim data1 as LineDataSerie= new LineDataSerie(d1,new LineStyle(1,Color.Blue,LineStyle.LINE_NORMAL)) |
9. add serie to chart | [C#] chart.addSerie(data1); [VB.NET] mychart.addSerie(data1) |
You can use the ChartLoader to create your charts using the parameters:
[c#]
// define variable
ChartLoader chartLoader= new ChartLoader();
// set chart parameters
chartLoader.setParameter("TITLECHART","Sales 2002");
chartLoader.setParameter("XLABEL","Month");
chartLoader.setParameter("YLABEL","Million $");
chartLoader.setParameter("XSCALE_MIN","0");
chartLoader.setParameter("XSCALE_MAX","5.5");
chartLoader.setParameter("YSCALE_MIN","-15");
chartLoader.setParameter("BIG_TICK_INTERVALX","1");
chartLoader.setParameter("BIG_TICK_INTERVALY","10"); chartLoader.setParameter("XAXIS_LABELS","June|July|Aug.|Sept.|Oct.|Nov.|Dec."); chartLoader.setParameter("CERO_XAXIS","LINE");
chartLoader.setParameter("YAXIS_INTEGER","TRUE");
chartLoader.setParameter("SERIE_1","Products");
chartLoader.setParameter("SERIE_2","Services");
chartLoader.setParameter("SERIE_TYPE_1","BAR");
chartLoader.setParameter("SERIE_TYPE_2","BAR");
chartLoader.setParameter("SERIE_FONT_1","Arial|PLAIN|8");
chartLoader.setParameter("SERIE_FONT_2","Arial|PLAIN|8");
chartLoader.setParameter("SERIE_DATA_1","12|43|50|45|30");
chartLoader.setParameter("SERIE_DATA_2","-10|41|48|39|36");
chartLoader.setParameter("SERIE_BORDER_TYPE_1","RAISED"); chartLoader.setParameter("SERIE_BORDER_TYPE_2","RAISED");
chartLoader.setParameter("SERIE_BAR_STYLE_1","ff00");
chartLoader.setParameter("SERIE_BAR_STYLE_2","ff");
chartLoader.setParameter("BARCHART_BARSPACE","1");
chartLoader.setParameter("LEFT_MARGIN","0.15");
chartLoader.setParameter("CHART_FILL","ffcc00");
chartLoader.setParameter("SERIE_NEGATIVE_STYLE_2","RED");
chartLoader.setParameter("YLABEL_VERTICAL","TRUE");
// create chart
Chart chart=chartLoader.buildChart();[VB.NET]
' define variable
dim chartLoader as ChartLoader = new ChartLoader()
' set chart parameters
chartLoader.setParameter("TITLECHART","Sales 2002")
chartLoader.setParameter("XLABEL","Month")
chartLoader.setParameter("YLABEL","Million $")
chartLoader.setParameter("XSCALE_MIN","0")
chartLoader.setParameter("XSCALE_MAX","5.5")
chartLoader.setParameter("YSCALE_MIN","-15")
chartLoader.setParameter("BIG_TICK_INTERVALX","1")
chartLoader.setParameter("BIG_TICK_INTERVALY","10") chartLoader.setParameter("XAXIS_LABELS","June|July|Aug.|Sept.|Oct.|Nov.|Dec.")
chartLoader.setParameter("CERO_XAXIS","LINE")
chartLoader.setParameter("YAXIS_INTEGER","TRUE")
chartLoader.setParameter("SERIE_1","Products")
chartLoader.setParameter("SERIE_2","Services")
chartLoader.setParameter("SERIE_TYPE_1","BAR")
chartLoader.setParameter("SERIE_TYPE_2","BAR")
chartLoader.setParameter("SERIE_FONT_1","Arial|PLAIN|8")
chartLoader.setParameter("SERIE_FONT_2","Arial|PLAIN|8")
chartLoader.setParameter("SERIE_DATA_1","12|43|50|45|30")
chartLoader.setParameter("SERIE_DATA_2","-10|41|48|39|36")
chartLoader.setParameter("SERIE_BORDER_TYPE_1","RAISED") chartLoader.setParameter("SERIE_BORDER_TYPE_2","RAISED")
chartLoader.setParameter("SERIE_BAR_STYLE_1","ff00")
chartLoader.setParameter("SERIE_BAR_STYLE_2","ff")
chartLoader.setParameter("BARCHART_BARSPACE","1")
chartLoader.setParameter("LEFT_MARGIN","0.15")
chartLoader.setParameter("CHART_FILL","ffcc00")
chartLoader.setParameter("SERIE_NEGATIVE_STYLE_2","RED")
chartLoader.setParameter("YLABEL_VERTICAL","TRUE")
' create chart
dim mychart as Chart mychart=chartLoader.buildChart()
You can also read the parameters directly from a file:
[c#]
// define variable
ChartLoader chartLoader= new ChartLoader();
// set chart parameters
chartLoader.loadFromFile("params.txt",true);
// create chart
Chart chart=chartLoader.buildChart();
In all cases the steps are:
RChart can create the following image files: JPG, PNG and GIF. This can be done by executing chart.saveToFile(filename,format), where format can be "JPEG", "PNG" of "GIF".
[c#]
// define variable
ChartLoader chartLoader= new ChartLoader();
// set chart parameters
chartLoader.loadFromFile("params.txt",true);
// create chart
Chart chart=chartLoader.buildChart();
chart.saveToFile("chart.gif","GIF");
If you want to receive an event when the user click on one of the bars or points you must implement the EventListener interface. The interface has only one method:
void userClick(String serie,int point);
which will be executed when the user clicks on the points or bars of you chart. In this case the method is executed and receives:
You must also set the listener like this:
ChartControl.eventListener=yourListener;
If you need to refresh you chart every X seconds to display changing data you can do it like this:
In order to recompile RChart you can use the following command:
csc.exe /unsafe /reference:system.dll /reference:system.data.dll /reference:System.Drawing.dll /reference:System.Windows.Forms.dll /target:library /out:rchart11.dll /nologo /debug- ODBCSource.cs Axis.cs AxisLabel.cs AssemblyInfo.cs ChartMapWebControl.cs BarDataSerie.cs BarPlotter3D.cs Chart.cs ChartComponent.cs ChartListener.cs ChartLoader.cs CurvePlotter.cs Legend.cs LineDataSerie.cs LinePlotter3D.cs LinePlotter.cs LogScale.cs MaxMinDataSerie.cs PieDataSerie.cs Plotter.cs RadarPlotter.cs RMatrix.cs Scale.cs Title.cs Vector.cs FillStyle.cs DataSerie.cs LineStyle.cs BarPlotter.cs PiePlotter.cs HAxisLabel.cs VAxisLabel.cs Polygon.cs Util.cs RValue.cs ChartControl.cs ChartWebControl.cs EventListener.cs
If you just want to recompile the example application:
csc.exe /unsafe /reference:system.dll /reference:system.data.dll /reference:System.Drawing.dll /reference:System.Windows.Forms.dll /reference:rchart11.dll /out:chartviewer11.exe /nologo /debug- Main.cs ChartViewer.cs