Combining different plots

A free public discussion forum for the JFreeChart class library.

Combining different plots

Postby spross » Tue Apr 10, 2007 10:49 am

Hi all

i'm new with jfreechart and i'm confused in combining different plots... the documentation and the demo code coudn't explain me that enough.

i wanna plot a chart with three areas and two lines... is the following way wrong?

1. i creat two XYSeriesCollection. One for the areas and one for the lines...
2. i creat the first XYSeries and add them to the area collection
3. i creat the second XYSeries and add them to the area collection too
4. i creat two XYSeries for the lines and add them to the line collection...

now i have two datasets (daAreas, daLines) which are XYSeriesCollections.
now i tried following:


Code: Select all
XYItemRenderer areaRenderer = new XYAreaRenderer();
   XYPlot plot = new XYPlot(
   daAreas,
        new NumberAxis(),
        null,
        areaRenderer
);

StandardXYItemRenderer lineRenderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES);
plot.setDataset(1, daLines);
plot.setRenderer(1, lineRenderer);   plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

JFreeChart chart = new JFreeChart(
        "title",
        JFreeChart.DEFAULT_TITLE_FONT,
        plot,
        true  // legend
);


Thx for help!
spross
spross
 
Posts: 8
Joined: Thu Apr 05, 2007 10:47 am

Postby david.gilbert » Tue Apr 10, 2007 11:10 am

Are you overlaying all the data within a single plot? If yes, then the only problem you have is that the range axis in the XYPlot is null (it needs a non-null axis - the only time you want a null axis is when there are multiple subplots that share a common axis (e.g. in CombinedRangeXYPlot)).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11199
Joined: Fri Mar 14, 2003 10:29 am

Postby spross » Tue Apr 10, 2007 11:24 am

ok thx! that was a copy-paste fault :P now the nullpointer exception is away :)

just a few more questions:

1. my data begins at 50 on the x axis and ends at 170... but on the left side the x axis begins at 0. thats waste of space at the moment. can i set the start point?

2. if i set no foregroundalpha, how can i define the order of the layers? means, area one is behind area two and line one is in front of line two?

3. how can i define specific colors for this layers?

thx!
spross
 
Posts: 8
Joined: Thu Apr 05, 2007 10:47 am

Postby david.gilbert » Tue Apr 10, 2007 11:32 am

spross wrote:1. my data begins at 50 on the x axis and ends at 170... but on the left side the x axis begins at 0. thats waste of space at the moment. can i set the start point?


Zero is included in the auto-range by default. Call setAutoRangeIncludesZero(false) on the axis.

spross wrote:2. if i set no foregroundalpha, how can i define the order of the layers? means, area one is behind area two and line one is in front of line two?


There are two methods in XYPlot that you can use to influence this:

setDatasetRenderingOrder();
setSeriesRenderingOrder();

Beyond those, you need to be careful about the order you add the series to the datasets.

spross wrote:3. how can i define specific colors for this layers?


The colours are defined in each renderer. JFreeChart will allocate default colours, but you can change those at any time.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11199
Joined: Fri Mar 14, 2003 10:29 am

Postby spross » Tue Apr 10, 2007 12:37 pm

first, thank you very much for your support!

1. if i setAutoRangeIncludesZero(false), it looks likes it works. but if i zoom out (left-click and pull the mouse top-left) the "zero-spaces" are there again :(

2. i can solve de ordering with the order of add the series, that works...

3. Ah i got it:
Code: Select all
XYItemRenderer areaRenderer = new XYAreaRenderer();
areaRenderer.setSeriesPaint(0, Color.GRAY);
areaRenderer.setSeriesPaint(1, Color.GREEN);


4. the quality of the chart is strange:
Image

- 1. the line is not realy straight. but the yellow dataset looks like (0,0;1,1;2,2;3,3;..170,170)
- 2. the green line is dashed, that's strange...

a closer view:

Image

thx a lot!
spross
 
Posts: 8
Joined: Thu Apr 05, 2007 10:47 am


Return to JFreeChart - General

Who is online

Users browsing this forum: No registered users and 10 guests