0

i'm trying to make an overlaid plot, And my problem is that i can't bring the second plot to fit the second one. Here is my first plot : enter image description here

And here the second one : enter image description here

And when i try to fit both, here is what i get :

enter image description here

So basically, i would like to fit the whole second plot between 0 and 30, how can i do this without losing any data?

First I tried using plot.mapDatasetToRangeAxis()

Then i tried with :

 domain.setRange(0.00, 30.0);
 domain.setTickUnit(new NumberTickUnit(1)); 

But i couldn't bring neither the first, nor the second one to work as i wish. Do you have any other ideas? (except buying this - which i can't afford right now as a student). Any help will be greatly appreciated :)

Oh and by the way the x-axis is a speed (forgot to draw it on the plot).

So here a very ugly photomontage of the kind of result i wish to have (with fitting units on the x and y axis) : Sorry for my Gimp skills, which are beyond bad. enter image description here

Here is what i did :

    private JFreeChart createOverlaidChart() 
{
    final NumberAxis domainAxis = new NumberAxis("Speed (m / s)");
    final ValueAxis rangeAxis = new NumberAxis("Power (kw)");

    // create plot ...
    final IntervalXYDataset data0 = createDataset0();
    final XYItemRenderer renderer0 = new XYBarRenderer(0.20);
    // change "new XYBarRenderer(0.20)" to "StandardXYItemRenderer()" if you want to change  type of graph
    final XYPlot plot = new XYPlot(data0, domainAxis, rangeAxis, renderer0);

    // add a second dataset and renderer... 
    final IntervalXYDataset data1 = createDataset1();
    final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(false, true); 
    // arguments of new XYLineAndShapeRenderer are to activate or deactivate the display of points or line. Set first argument to true if you want to draw lines between the points for e.g.
    plot.setDataset(1, data1);
    plot.setRenderer(1, renderer1);

    // add a third dataset and renderer... 
    final IntervalXYDataset data2 = createDataset2();
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, true); 
    // arguments of new XYLineAndShapeRenderer are to activate or deactivate the display of points or line. Set first argument to true if you want to draw lines between the points for e.g.
    plot.setDataset(2, data2);
    plot.setRenderer(2, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("Test", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
trolologuy
  • 1,900
  • 4
  • 21
  • 32

2 Answers2

1

The Range Axis is the Vertical/Y Axis, you need to add a second Domain Axis (Horizontal/X Axis) to your chart.

Community
  • 1
  • 1
GrahamA
  • 5,875
  • 29
  • 39
  • The point is that i want to use the same axis... is it even possible? or did i understood you wrong? ( i added my code) – trolologuy Sep 20 '13 at 12:16
  • @trolologuy The first (green) dataset domain is 0-31 and the second (red) dataset domain is 0-4500) so when you plot both datasets on the same axis the first appears squashed. To create you desired ploy you need to either have to axes or map the domain of the first dataset to the second; for example if the first dataset where in seconds and the second in milliseconds you could convert on set of domain valves – GrahamA Sep 20 '13 at 12:54
  • Okey, but how can i map the first dataset to the second? – trolologuy Sep 20 '13 at 12:56
  • @trolologuy what are the units of the two domains 0-31 and 0-4500 I can see that the Range is in Kw – GrahamA Sep 20 '13 at 13:12
  • The unit should be m/s (meter per second as a speed), but for the second plot it is obviously not in m/s. I don't really now either in what a unit it is displayed...(i'm a bit confused). I think it's simply the number of points, because i made a custom array with my points and he shows as a x-axis unit the number of points i have used. – trolologuy Sep 20 '13 at 13:21
  • I checked, and yes on the second plot the x-axis unit is the number of points. – trolologuy Sep 20 '13 at 13:27
  • You really need to know what the units are for your second dataset. If you have just used integers from 0-4500 you can divide all the x/domain values by 150 so that the last reading has an x value of 30 to make the charts look right – GrahamA Sep 20 '13 at 13:34
  • hmmm, nearly worked though :/ It seems to change the form of the curve (it doesn't fit the standart curve). But thanks ! – trolologuy Sep 23 '13 at 07:34
0

I did something similar -- although using same X axis vales but differing Y axis. For this, I use single Domain (you'd want single Range). I convert for you (there may be typos due to my edits):

        priceXYPlot.setRangeAxis( new new NumberAxis( "Y" ) );
        priceXYPlot.setDomainAxis( 0, new NumberAxis( "X1" ) );
        priceXYPlot.setDomainAxis( 1, new NumberAxis("X2") );

and mapDatasetToRangeAxis so that you had two diff X axis along top & bottom, something like:

        priceXYPlot.setDataset( 0, data0);
        priceXYPlot.mapDatasetToDomainAxis( 0, 0 ); //1st dataset to 1st x-axis
        priceXYPlot.setDataset( 1, data1 );
        priceXYPlot.mapDatasetToDomainAxis( 1, 1 ); //2nd dataset to 2nd x-axis

shared x axis, two Y axis plots

james_t
  • 255
  • 1
  • 10