Line Chart Sample not working
David Han <[email protected]>
| Newsgroups | gmane.comp.krysalis.jcharts.user |
|---|---|
| Message-ID | <a0521062cbc722891e23f@[128.183.190.142]> |
I cut and pasted the line chart sample that came with the User's
Guide. The program compiles fine, but it doesn't draw anything. Do
I need to call some more APIs before I can draw a line chart? Here's
my program. I'd appreciate for any help. Thanks much in advance.
import org.jCharts.Chart;
import org.jCharts.axisChart.AxisChart;
import org.jCharts.chartData.DataSeries;
import org.jCharts.chartData.DataSet;
import org.jCharts.chartData.AxisChartDataSet;
import org.jCharts.types.ChartType;
import org.jCharts.properties.*;
import org.jCharts.properties.LineChartProperties;
import org.jCharts.properties.PointChartProperties;
import org.jCharts.chartData.ChartDataException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
public class LineChart extends JFrame
{
private JPanel panel;
private static int width = 450;
private static int height = 450;
private void LineChart () throws ChartDataException, PropertyException
{
initComponents();
}
private void initComponents() throws ChartDataException, PropertyException
{
this.setSize( width, height );
this.panel = new JPanel( true );
this.panel.setSize( width, height );
this.getContentPane().add( this.panel );
this.setVisible( true );
String[] xAxisLabels = { "1998", "1999", "2000", "2001",
"2002", "2003", "2004" };
String xAxisTitle = "Years";
String yAxisTitle = "Problems";
String title = "Micro$haft at Work";
DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
yAxisTitle, title );
double[][] data = new double[][]{ { 250, 45, -36, 66, 145, 80, 55 } };
String[] legendLabels = { "Bugs" };
Paint[] paints = {Color.blue};
Stroke[] strokes= { LineChartProperties.DEFAULT_LINE_STROKE };
Shape[] shapes= { PointChartProperties.SHAPE_CIRCLE };
LineChartProperties properties = new
LineChartProperties(strokes, shapes);
AxisChartDataSet axisChartDataSet =
new AxisChartDataSet(data, legendLabels, paints, ChartType.LINE,
properties );
dataSeries.addIAxisPlotDataSet (axisChartDataSet);
ChartProperties chartProperties = new ChartProperties();
AxisProperties axisProperties = new AxisProperties();
LegendProperties legendProperties = new LegendProperties();
AxisChart axisChart= new AxisChart(dataSeries, chartProperties,
axisProperties, legendProperties,
width, height);
addWindowListener( new java.awt.event.WindowAdapter()
{
public void windowClosing( WindowEvent windowEvent )
{
System.exit( 0 );
}
}
);
}
/*********************************************************************
* Main
*********************************************************************/
public static void main (String args[] )
throws ChartDataException, PropertyException
{
new LineChart();
}
}
--
David Han
[email protected]
301-286-3617
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click