Marking Points on XYSeries, a diff. point for each series
Marking Points on XYSeries, a diff. point for each series
Hi,
I created XYLineChart which simply displays the series in different colors. How can I mark the points on the serires? For example for Series1, I want to mark circles, series2 I want to mark rectangles?
Thanks in Advance,
gayatri.
I created XYLineChart which simply displays the series in different colors. How can I mark the points on the serires? For example for Series1, I want to mark circles, series2 I want to mark rectangles?
Thanks in Advance,
gayatri.
Re: Marking Points on XYSeries, a diff. point for each serie
Hi ,gayatri ganpaa wrote: Hi,
I created XYLineChart which simply displays the series in different colors.
Could you tell me how to do this
I have some trouble with this >"<
Is it like " one line in different colors " ??
Thank you !!!
chart = ChartFactory.createXYLineChart("demo", "tuples","replication",coll,PlotOrientation.VERTICAL,true,true,true); //coll is XYSEriesCollection
//chart = ChartFactory.createTimeSeriesChart("demo", "tuples","replication",data,PlotOrientation.VERTICAL,true,true,true);
File f = new File(fileName);
f.createNewFile();
ChartUtilities.saveChartAsJPEG(f,chart,640,480);
//which creates each series
public void createSeries(Vector vec_x, Vector vec_y, String seriesName) throws IOException{
XYSeries series1 = new XYSeries(seriesName,true,false);
addData(series1,vec_x,vec_y);
coll.addSeries(series1);
}
//chart = ChartFactory.createTimeSeriesChart("demo", "tuples","replication",data,PlotOrientation.VERTICAL,true,true,true);
File f = new File(fileName);
f.createNewFile();
ChartUtilities.saveChartAsJPEG(f,chart,640,480);
//which creates each series
public void createSeries(Vector vec_x, Vector vec_y, String seriesName) throws IOException{
XYSeries series1 = new XYSeries(seriesName,true,false);
addData(series1,vec_x,vec_y);
coll.addSeries(series1);
}
Hi,gayatri ganpaa:gayatri ganpaa wrote:
//which creates each series
public void createSeries(Vector vec_x, Vector vec_y, String seriesName) throws IOException{
XYSeries series1 = new XYSeries(seriesName,true,false);
addData(series1,vec_x,vec_y);
coll.addSeries(series1);
}
It's me again.
First,I'm appreciate your answer.

But I have no idea about this code
Code: Select all
addData(series1,vec_x,vec_y);

Is it a method in XYSeries

I cannot fine it in JFreeChart API Doc

Thank you
Hi,dhchoudhchou wrote:
You can use XYLineAndShapeRenderer.setShapesVisible(java.lang.Boolean visible) to display shapes on the data points.
However, if you want to customize the shape for individual series, you may need to subclass the renderer and overwrite the method that draws shapes.
Daniel

thanks for answer me
I'm new for JFreeChart
SO ..I have no idea about you said "you may need to subclass the renderer and overwrite the method that draws shapes."
Do you have any example code let me know more about it
ps My English is very bad,I am sorry about this.

Your English is fine. Let me rephrase what I said before.
You should try the XYLineAndShapeRenderer.setShapesVisible(java.lang.Boolean visible) method and see if the result is what you wanted. If you want to change the shapes, you need to write a separate class that extends XYLineAndShapeRenderer.
Daniel
You should try the XYLineAndShapeRenderer.setShapesVisible(java.lang.Boolean visible) method and see if the result is what you wanted. If you want to change the shapes, you need to write a separate class that extends XYLineAndShapeRenderer.
Daniel
extending class
Daniel - I understand it when you say I need to extend the class.
But wouldnt that cause a problem with other classes which use
the base class.
How do I find out all the classes that are using my base class.
The JFreeChart class does not use the
"XYLineAndShapeRenderer"
class directly. I am assuming one of the listeners is calling this class
as data is being added to the JFreeChart object.
Ajay
But wouldnt that cause a problem with other classes which use
the base class.
How do I find out all the classes that are using my base class.
The JFreeChart class does not use the
"XYLineAndShapeRenderer"
class directly. I am assuming one of the listeners is calling this class
as data is being added to the JFreeChart object.
Ajay
When you extend a class, you create a separate class file. So other classes that want to use the base class would just call the original renderer class in JFreeChart, not your new class.
Also, JFreeChart contains a Plot instance. Each specific type of Plot (for example XYPlot) is associated with a renderer.
Daniel
Also, JFreeChart contains a Plot instance. Each specific type of Plot (for example XYPlot) is associated with a renderer.
Daniel
Here are some pieced together snippets from my project. They may not compile, but they should give you and idea of what I've been able to do without subclassing.
/* Create chart with our data points */
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
XYPlot plot = (XYPlot) chart.getPlot();
/* Turn on scatter plot with our custom points */
XYItemRenderer renderer = plot.getRenderer();
StandardXYItemRenderer xyRenderer = (StandardXYItemRenderer)renderer;
xyRenderer.setPlotShapes(true);
//This does what you want, keep going only if you need to control the shapes and colors used in your plot. Note changes made this way may or may not be reflected in the legend.
// Triangle
GeneralPath s5 = new GeneralPath();
s5.moveTo(0.0f, -3.0f);
s5.lineTo(3.0f, 3.0f);
s5.lineTo(-3.0f, 3.0f);
s5.closePath();
xyRenderer.setSeriesShape(0, s5);
xyRenderer.setSeriesPaint(0, Color.BLUE);
xyRenderer.setSeriesShape(1, s5);
xyRenderer.setSeriesPaint(1, Color.GREEN);
/* Create chart with our data points */
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
XYPlot plot = (XYPlot) chart.getPlot();
/* Turn on scatter plot with our custom points */
XYItemRenderer renderer = plot.getRenderer();
StandardXYItemRenderer xyRenderer = (StandardXYItemRenderer)renderer;
xyRenderer.setPlotShapes(true);
//This does what you want, keep going only if you need to control the shapes and colors used in your plot. Note changes made this way may or may not be reflected in the legend.
// Triangle
GeneralPath s5 = new GeneralPath();
s5.moveTo(0.0f, -3.0f);
s5.lineTo(3.0f, 3.0f);
s5.lineTo(-3.0f, 3.0f);
s5.closePath();
xyRenderer.setSeriesShape(0, s5);
xyRenderer.setSeriesPaint(0, Color.BLUE);
xyRenderer.setSeriesShape(1, s5);
xyRenderer.setSeriesPaint(1, Color.GREEN);