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
How to draw a shape to represent a Data point on the Line ch
Re: How to draw a shape to represent a Data point on the Lin
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...
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...
Re: How to draw a shape to represent a Data point on the Lin
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
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
Re: How to draw a shape to represent a Data point on the Lin
For now you have to override StandardXYItemRenderer and return true from the isShapeFilled method...at some point I'll make this easier.
Regards,
DG.
Regards,
DG.
Re: How to draw a shape to represent a Data point on the Lin
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
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
Re: How to draw a shape to represent a Data point on the Lin
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