Marker Size

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
miladirooni
Posts: 24
Joined: Fri Sep 04, 2009 10:28 am
antibot: No, of course not.

Marker Size

Post by miladirooni » Tue Feb 16, 2010 4:56 pm

Hi

Is there any way that i could set the markers size in jfreechart? because My chart contains 100,000 of data which size of the markers causes the plot to be packed together which can not be read clearly unless is zoomed in.

tanx

dweems
Posts: 12
Joined: Sat Feb 20, 2010 9:59 pm
antibot: No, of course not.

Re: Marker Size

Post by dweems » Sat Feb 20, 2010 10:39 pm

I'm having the same problem. I tried the following code that logically looks like it should work but doesn't. I'm curious why it doesn't.

Code: Select all

JFreeChart chart = 
      ChartFactory.createTimeSeriesChart( "",                 // title
                                          "Date",             // x-axis label
                                          "Price",            // y-axis label
                                          this.upperDataSet,  // data
                                          true,               // create legend?
                                          true,               // generate tooltips?
                                          false               // generate URLs?
      );
XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible( true );
renderer.setBaseShapesFilled( true );
Shape shape = renderer.lookupSeriesShape( 0 );
Rectangle rect = shape.getBounds();
rect.setBounds( -1, -1, 2, 2 );
My debugger indicates that the Shape is a Rectangle2D$Double with x = -3.0, y = -3.0; width = 6.0 and height = 6.0. I figured making the rectangle 1/3 the original size would look much better, hence the values of ( -1, -1, 2, 2 ). To get greater resolution I also tried retrieving the Rectangle2D via getBounds2D method and then issuing rect2D.setRect( -1.0, -1,0, 2.0, 2.0 ) instead but that didn't help. I can set the Rectangle/Rectangle2D values but changing them has no effect on the Shape attributes. Obviously I'm missing something here.

I would also like to be able define the markers and their colors for each series rather than going with the defaults. I can't find anything on that in the JFreeChart documentation or the Java 6 API. I'm hoping that if someone provides a solution to this resize problem, setting the other attributes will become evident.

dweems
Posts: 12
Joined: Sat Feb 20, 2010 9:59 pm
antibot: No, of course not.

Re: Marker Size

Post by dweems » Sun Feb 21, 2010 8:52 am

Solution: I was close before but you have to replace the Shape in the XYLineAndShapeRenderer rather than modifying the existing one, which you apparently can't do. Getting the Shape in my earlier posting showed that the default shape for series 0 is a Rectangle2D.Double. For other series you'll need to determine the specific Shape or replace it with your choice. Here's the code to make the first series marker smaller. Play with the rectangle coordinates (x, y, width, height) to get the size you want. Note that these are relative to the origin (0,0) of the Shape (i.e. marker), not the coordinates on the line.

Code: Select all

JFreeChart chart = 
ChartFactory.createTimeSeriesChart( "",                 // title
                                          "Date",             // x-axis label
                                          "Price",            // y-axis label
                                          this.upperDataSet,  // data
                                          true,               // create legend?
                                          true,               // generate tooltips?
                                          false               // generate URLs?
      );
XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setSeriesShapesVisible( 0, true );
renderer.setSeriesShape( 0, new Rectangle2D.Double( -1.0, -1.0, 2.0, 2.0 ) );

miladirooni
Posts: 24
Joined: Fri Sep 04, 2009 10:28 am
antibot: No, of course not.

Re: Marker Size

Post by miladirooni » Mon Feb 22, 2010 12:47 pm

Sweet tanx for replying.

Locked