How to draw a shape to represent a Data point on the Line ch

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Satish

How to draw a shape to represent a Data point on the Line ch

Post by Satish » Thu Jul 18, 2002 9:13 pm

Hi,

I am drawing a simple line chart. I could able to draw the chart,
except the problem mentioned below. Could some body suggest
what needs to be done.

Problem: I need to represent each Data point with some shape like little Square or a Solid Circle.

Part of source code related to chart is as follows:

public void drawGraph() {
String xAxisLabel = "Date Time";
String yAxisLabel = "Value";
Paint[] seriesP = new Paint[] {Color.blue, Color.green};

try {
ValueAxis timeAxis = new HorizontalDateAxis(xAxisLabel);
((HorizontalDateAxis)timeAxis).setTickUnit(new DateUnit(12,15));
((HorizontalDateAxis)timeAxis).setVerticalTickLabels(true);
NumberAxis valueAxis = new VerticalNumberAxis(yAxisLabel);
valueAxis.setAutoRangeIncludesZero(false);
valueAxis.setLabelFont(new Font("Dialog",Font.BOLD,10));
valueAxis.setLowerMargin(0.1);

String title = new String("TEST_Data"));
chart = ChartFactory.createTimeSeriesChart(title,xAxisLabel, yAxisLabel,dataSet,true);
chart.getPlot().setSeriesPaint(seriesP);
chart.setBackgroundPaint(Color.cyan);
}
catch (AxisNotCompatibleException e) {
...
}
catch (PlotNotCompatibleException e) {
...
}
catch (Exception ex) {
...
}
chartPanel = new ChartPanel(chart, true, true, true, true, true);
chartPanel.setPreferredSize(new Dimension(800, 350));
panel.add(chartPanel);
}

Please suggest.

thanks
Satish

Richard Atkinson

Re: How to draw a shape to represent a Data point on the Lin

Post by Richard Atkinson » Fri Jul 19, 2002 8:15 am

Satish,

Here is some code to create XY charts with lines and symbols.

// Create the chart
ValueAxis timeAxis = new HorizontalDateAxis("");
NumberAxis valueAxis = new VerticalNumberAxis("");
valueAxis.setAutoRangeIncludesZero(false); // override default
XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis);
StandardXYItemRenderer sxyir = new StandardXYItemRenderer(
StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES,
new StandardXYToolTipGenerator());
plot.setXYItemRenderer(sxyir);
JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT,
plot, false);
chart.setBackgroundPaint(java.awt.Color.white);

See http://homepage.ntlworld.com/richard_c_ ... freechart/ for an example of the output.

Regards,
Richard...

Satish

Re: How to draw a shape to represent a Data point on the Lin

Post by Satish » Sun Jul 21, 2002 8:38 pm

Hi Richard,

Thank you very much for your suggestion. your solution worked fine.

However I had 2 little gitches.

1. The shape of the data points were hallow instead of SOLID square and circles.

I have tried and but could not get it right.

2. The Tick marks for the Horizantal axis (time axis), were shown for every
minute interval.

I needed an interval of 15-Minutes.

Could you also suggest me How to show the TickMarks for the DataPoints
say for every 15 pixels.

Thanks again. I appreciate you help.

satish

David Gilbert

Re: How to draw a shape to represent a Data point on the Lin

Post by David Gilbert » Mon Jul 22, 2002 12:01 pm

For now you have to override StandardXYItemRenderer and return true from the isShapeFilled method...at some point I'll make this easier.

Regards,

DG.

Tom Mazzotta

Re: How to draw a shape to represent a Data point on the Lin

Post by Tom Mazzotta » Fri Jan 31, 2003 8:48 pm

How would I modify this code so that it will work with a Line Chart instead of an XYChart?

for example:

chart = ChartFactory.createLineChart(sChartTitle,sXAxisLabel,sYAxisLabel,categoryDataset,true);

CategoryPlot plot = chart.getCategoryPlot();

//I Want to do something like this, but with a linechart, not an XYChart...
StandardXYItemRenderer sxyir = new StandardXYItemRenderer(StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES);

chart.getXYPlot().setRenderer(sxyir);

//I tried the following types of things, but the methods don't exist:
CategoryItemRenderer catIR= new CategoryItemRenderer (CategoryItemRenderer .LINES + CategoryItemRenderer .SHAPES);
plot.setRenderer(catIR);

thank you in advance

Tom Mazzotta

Re: How to draw a shape to represent a Data point on the Lin

Post by Tom Mazzotta » Fri Jan 31, 2003 9:03 pm

Sorry - I just figured out the answer to my question.... I'm not sure how I missed it the first time... need to use the LineAndShapeRenderer class

Locked