Marking Points on XYSeries, a diff. point for each series

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

Marking Points on XYSeries, a diff. point for each series

Post by gayatri ganpaa » Tue Aug 02, 2005 10:56 pm

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.

tony01
Posts: 5
Joined: Tue Aug 02, 2005 12:44 pm

Re: Marking Points on XYSeries, a diff. point for each serie

Post by tony01 » Wed Aug 03, 2005 5:06 am

gayatri ganpaa wrote: Hi,

I created XYLineChart which simply displays the series in different colors.
Hi ,
Could you tell me how to do this

I have some trouble with this >"<

Is it like " one line in different colors " ??

Thank you !!!

dhchou
Posts: 138
Joined: Tue Jul 05, 2005 11:01 pm

Post by dhchou » Wed Aug 03, 2005 3:50 pm

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

gayatri ganpaa

Post by gayatri ganpaa » Wed Aug 03, 2005 7:10 pm

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);

}

Guest

Post by Guest » Thu Aug 04, 2005 3:07 am

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);

}
Hi,gayatri ganpaa:

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);
What is this? :shock:
Is it a method in XYSeries :?:
I cannot fine it in JFreeChart API Doc :!:

Thank you

tony01
Posts: 5
Joined: Tue Aug 02, 2005 12:44 pm

Post by tony01 » Thu Aug 04, 2005 3:15 am

dhchou 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
Hi,dhchou :)
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. :oops:

dhchou
Posts: 138
Joined: Tue Jul 05, 2005 11:01 pm

Post by dhchou » Fri Aug 05, 2005 5:07 pm

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

jolly_guy

extending class

Post by jolly_guy » Fri Aug 05, 2005 7:33 pm

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

dhchou
Posts: 138
Joined: Tue Jul 05, 2005 11:01 pm

Post by dhchou » Mon Aug 08, 2005 6:30 pm

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

fowlerje
Posts: 3
Joined: Mon Aug 08, 2005 6:58 pm

Post by fowlerje » Mon Aug 08, 2005 7:30 pm

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);

guest1210

Post by guest1210 » Mon Aug 15, 2005 8:39 pm

public void addData(XYSeries series, Vector vecx, Vector vecy) {
for(int i=0;i<vecx.size();i++){
series.add(Integer.valueOf(""+vecx.get(i)),Double.valueOf(""+vecy.get(i)));
}

}


addData is made by me.

Gayatri Ganpaa

Locked