Creatting a Area Chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jesusmgmarin
Posts: 13
Joined: Thu Apr 20, 2006 2:24 pm
Location: Spain
Contact:

Creatting a Area Chart

Post by jesusmgmarin » Tue Jul 04, 2006 4:02 pm

hi, I have a java class that creates a chart (Area Chart). To create the "dataset" I use a variable (arrayVars) that contains the data, but the chart is not create Ok, I want only one area in the chart, but with this code creates an area by each row.
(I want in X-axis the values of column 0 and in the Y-axis the values of column 1, the variable arrayVars has 2 cols and several cols)


My code is:

Code: Select all

public JFreeChart OneColorChart(String vInDep, String vDep){
// create a dataset...
    final double[][] data = new double[arrayVars.length][arrayVars[0].length];
		
    /* Recorremos el array bidimensional  añadiéndolo al chart, siempre y cuando no exista valor nulo por fila	*/
    for (int i=0; i<arrayVars.length; i++)
    {
        for(int j=0; j<arrayVars[0].length; j++)
        {
            if( (null != arrayVars[i][0]) && (null != arrayVars[i][1]) )
            {
	data[i][j] = Double.parseDouble(arrayVars[i][j]);
            }
        }
    }
		
    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
            "Series ", "Type ", data
        );
		
    final JFreeChart chart = ChartFactory.createAreaChart(
            "Area Chart",             // chart title
            "Category",               // domain axis label
            "Value",                  // range axis label
            dataset,                  // data
            PlotOrientation.VERTICAL, // orientation
            true,                     // include legend
            true,                     // tooltips
            false                     // urls
    );
    
    return chart;    
}
The variable arrayVars contains data, It is a variable of the session.

Badly is filled up the variable data?,

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jul 05, 2006 1:52 pm

I'd recommend creating a new instance of DefaultCategoryDataset and populating it via the methods of that class, rather than messing about with arrays of arrays.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked