Strange grid behavior at overlaid chart

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

Strange grid behavior at overlaid chart

Post by Dmitry Bessonov » Mon Apr 15, 2002 10:23 am

Hi,

I have created an overlaid chart with several xySeriesDatasets the same way as it is shown in JFreeChartDemo. At first it worked ok and looked great,

http://dbessonov.mailru.com/right.gif

but when I changed size of the chart I saw strange grid and series behavior.

http://dbessonov.mailru.com/wrong.gif

Does anybody can tell me, what have I done wrong?

Dmitry.

David Gilbert

Re: Strange grid behavior at overlaid chart

Post by David Gilbert » Mon Apr 15, 2002 11:46 am

Hi Dmitry,

I see the problem, but I'm not sure what the cause is. Can you post some code that replicates the problem, and I will take a look at it?

Regards,

DG.

Dmitry Bessonov

Re: Strange grid behavior at overlaid chart

Post by Dmitry Bessonov » Mon Apr 15, 2002 12:33 pm

Hi Gilbert,

Thank you for reply.
Here is the code and some comments : I have 3 data series added to 'frontiersCollection' and 4 data series (containing three data points each) added to 'dataPoints' (color spots at the picture).
(DataPointDataset extends AbstractSeriesDataset implements XYDataset)
Seems like every sub plot, added to overlaid plot comes with its own grid.

-------------------------

XYSeriesCollection frontiersCollection = new XYSeriesCollection();
........
DataPointDataset dataPoints = new DataPointDataset();

// creating combined dataset
CombinedDataset combinedData = new CombinedDataset();
combinedData.add(frontiersCollection);
combinedData.add(dataPoints);
// decompose data
SeriesDataset seriesEFUpper = new SubSeriesDataset(combinedData, 0);
SeriesDataset seriesEFMiddle = new SubSeriesDataset(combinedData, 1);
SeriesDataset seriesEFLower = new SubSeriesDataset(combinedData, 2);
SeriesDataset seriesDPLeft = new SubSeriesDataset(combinedData, 3);
SeriesDataset seriesDPRight = new SubSeriesDataset(combinedData, 4);
SeriesDataset seriesDPOptimal = new SubSeriesDataset(combinedData, 5);
SeriesDataset seriesDPPortfolio = new SubSeriesDataset(combinedData, 6);

// common horizontal and vertical axes
NumberAxis horAxis = new HorizontalNumberAxis("Ðèñê (%)");
horAxis.setCrosshairVisible(false);
horAxis.setAutoRangeIncludesZero(false);
horAxis.setAutoRangeStickyZero(false);

NumberAxis vertAxis = new VerticalNumberAxis("Äîõîäíîñòü (%)");
vertAxis.setCrosshairVisible(false);
vertAxis.setAutoRangeIncludesZero(false);
vertAxis.setAutoRangeStickyZero(false);

// make an overlaid CombinedPlot
CombinedPlot overlaidPlot = new CombinedPlot(horAxis, vertAxis);
CombinedChart frontierUpperChart = ChartFactory.createCombinableXYChart(horAxis, vertAxis, seriesEFUpper);
CombinedChart frontierMiddleChart = ChartFactory.createCombinableXYChart(horAxis, vertAxis, seriesEFMiddle);
CombinedChart frontierLowerChart = ChartFactory.createCombinableXYChart(horAxis, vertAxis, seriesEFLower);

CombinedChart dpChartLeft = ChartFactory.createCombinableXYChart(horAxis, vertAxis, seriesDPLeft);
CombinedChart dpChartRight = ChartFactory.createCombinableXYChart(horAxis, vertAxis, seriesDPRight);
CombinedChart dpChartOptimal = ChartFactory.createCombinableXYChart(horAxis, vertAxis, seriesDPOptimal);
CombinedChart dpChartPortfolio = ChartFactory.createCombinableXYChart(horAxis, vertAxis, seriesDPPortfolio);

// setting renderers for points
XYPlot dpPlotLeft = (XYPlot)dpChartLeft.getPlot();
dpPlotLeft.setXYItemRenderer(new DataPointRenderer());
XYPlot dpPlotRight = (XYPlot)dpChartRight.getPlot();
dpPlotRight.setXYItemRenderer(new DataPointRenderer());
XYPlot dpPlotOpt = (XYPlot)dpChartOptimal.getPlot();
dpPlotOpt.setXYItemRenderer(new DataPointRenderer(12));
XYPlot dpPlotPortfolio = (XYPlot)dpChartPortfolio.getPlot();
dpPlotPortfolio.setXYItemRenderer(new DataPointRenderer());

// add the sub-plots
overlaidPlot.add(frontierUpperChart);
overlaidPlot.add(frontierMiddleChart);
overlaidPlot.add(frontierLowerChart);
overlaidPlot.add(dpChartLeft);
overlaidPlot.add(dpChartRight);
overlaidPlot.add(dpChartOptimal);
overlaidPlot.add(dpChartPortfolio);
// call this method after all sub-plots have been added
overlaidPlot.adjustPlots();

// make the top level JFreeChart object
chartEF = new JFreeChart(combinedData, overlaidPlot, "", JFreeChart.DEFAULT_TITLE_FONT, false);

Dmitry.

David Gilbert

Re: Strange grid behavior at overlaid chart

Post by David Gilbert » Wed Apr 17, 2002 9:50 am

Hi Dmitry,

I can't see any problem with your code, but I also can't reproduce the problem using the OverlaidPlotDemo class. Is there any chance you could try to modify OverlaidPlotDemo to reproduce the problem?

I'm sure that you have discovered a bug, but it is difficult for me to trace it without some running code, especially as I didn't write the overlaid plotting code.

Regards,

DG.

Dmitry Bessonov

Re: Strange grid behavior at overlaid chart

Post by Dmitry Bessonov » Wed Apr 17, 2002 3:23 pm

Hi Gilbert,

Thank you very much for support.
I have created hardcoded sample that shows the problem. Notice that frame resizing affects 'multiple grid effect'.
I used the latest libraries (6.1 / 8.1)

Here is the content of my sample 'Chart.java'

Dmitry.

------------------------


import com.jrefinery.chart.*;
import com.jrefinery.chart.combination.*;
import com.jrefinery.data.*;
import com.jrefinery.date.SerialDate;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.*;

public class Chart {

public static void main(String[] args) {

JFreeChart chartEF = null;

XYSeries dataSeriesEFUpper = new XYSeries("Upper frontier");
XYSeries dataSeriesEFMiddle = new XYSeries("Middle frontier");
XYSeries dataSeriesEFLower = new XYSeries ("Lower frontier");

XYSeriesCollection frontiersCollection = new XYSeriesCollection();

try {

dataSeriesEFUpper.add(2.0, 17.0);
dataSeriesEFUpper.add(1.98, 16.99);
dataSeriesEFUpper.add(1.96, 16.98);
dataSeriesEFUpper.add(1.94, 16.97);
dataSeriesEFUpper.add(1.92, 16.96);
dataSeriesEFUpper.add(1.9, 16.95);
dataSeriesEFUpper.add(0.1799999999999985, 16.089999999999996);
dataSeriesEFUpper.add(0.1599999999999985, 16.08);
dataSeriesEFUpper.add(0.13999999999999851, 16.069999999999997);
dataSeriesEFUpper.add(0.11999999999999851, 16.06);
dataSeriesEFUpper.add(0.0999999999999985, 16.049999999999997);
dataSeriesEFUpper.add(0.0799999999999985, 16.04);
dataSeriesEFUpper.add(0.0599999999999985, 16.029999999999998);
dataSeriesEFUpper.add(0.039999999999998495, 16.019999999999996);
dataSeriesEFUpper.add(0.019999999999998495, 16.009999999999998);


dataSeriesEFMiddle.add(3.0, 16.0);
dataSeriesEFMiddle.add(2.97875472760617, 15.99);
dataSeriesEFMiddle.add(2.95751743172758, 15.98);
dataSeriesEFMiddle.add(2.936288285439489, 15.969999999999999);
dataSeriesEFMiddle.add(2.915067466791485, 15.959999999999999);
dataSeriesEFMiddle.add(2.8938551589848722, 15.95);
dataSeriesEFMiddle.add(2.8726515505575807, 15.94);
dataSeriesEFMiddle.add(2.851456835576977, 15.93);
dataSeriesEFMiddle.add(2.8302712138409527, 15.919999999999998);
dataSeriesEFMiddle.add(0.98959105698609, 14.599999999999996);
dataSeriesEFMiddle.add(0.9894355173475977, 14.589999999999995);
dataSeriesEFMiddle.add(0.9893040608565782, 14.579999999999995);
dataSeriesEFMiddle.add(0.989196697114416, 14.569999999999995);
dataSeriesEFMiddle.add(0.9891134339665847, 14.559999999999993);
dataSeriesEFMiddle.add(0.9890542774997814, 14.549999999999995);
dataSeriesEFMiddle.add(0.9890192320397039, 14.539999999999994);
dataSeriesEFMiddle.add(0.9890083001494693, 14.529999999999996);


dataSeriesEFLower.add(4.0, 15.0);
dataSeriesEFLower.add(3.9775133696774625, 14.99);
dataSeriesEFLower.add(3.9550505631736246, 14.979999999999999);
dataSeriesEFLower.add(3.9326119887285005, 14.969999999999999);
dataSeriesEFLower.add(3.9101980635073126, 14.959999999999999);
dataSeriesEFLower.add(3.887809213831824, 14.95);
dataSeriesEFLower.add(1.9597175589394877, 13.589999999999995);
dataSeriesEFLower.add(1.9594269755464067, 13.579999999999995);
dataSeriesEFLower.add(1.9591850422682164, 13.569999999999995);
dataSeriesEFLower.add(1.9589917771296217, 13.559999999999995);
dataSeriesEFLower.add(1.9588471945358106, 13.549999999999994);
dataSeriesEFLower.add(1.9587513052670933, 13.539999999999994);
dataSeriesEFLower.add(1.9587041164748829, 13.529999999999994);

// composing three frontiers
frontiersCollection.addSeries(dataSeriesEFUpper);
frontiersCollection.addSeries(dataSeriesEFMiddle);
frontiersCollection.addSeries(dataSeriesEFLower);


// creating combined dataset
CombinedDataset combinedData = new CombinedDataset();
combinedData.add(frontiersCollection);
// decompose data
SeriesDataset seriesEFUpper = new SubSeriesDataset(combinedData, 0);
SeriesDataset seriesEFMiddle = new SubSeriesDataset(combinedData, 1);
SeriesDataset seriesEFLower = new SubSeriesDataset(combinedData, 2);

// common horizontal and vertical axes
NumberAxis horAxis = new HorizontalNumberAxis("Risk (%)");
horAxis.setCrosshairVisible(false);
horAxis.setAutoRangeIncludesZero(false);
horAxis.setAutoRangeStickyZero(false);

NumberAxis vertAxis = new VerticalNumberAxis("Return (%)");
vertAxis.setCrosshairVisible(false);
vertAxis.setAutoRangeIncludesZero(false);
vertAxis.setAutoRangeStickyZero(false);

// make an overlaid CombinedPlot
CombinedPlot overlaidPlot = new CombinedPlot(horAxis, vertAxis);
CombinedChart frontierUpperChart = ChartFactory.createCombinableXYChart(horAxis, vertAxis, seriesEFUpper);
CombinedChart frontierMiddleChart = ChartFactory.createCombinableXYChart(horAxis, vertAxis, seriesEFMiddle);
CombinedChart frontierLowerChart = ChartFactory.createCombinableXYChart(horAxis, vertAxis, seriesEFLower);

// add the sub-plots
overlaidPlot.add(frontierUpperChart);
overlaidPlot.add(frontierMiddleChart);
overlaidPlot.add(frontierLowerChart);
// call this method after all sub-plots have been added
overlaidPlot.adjustPlots();

// make the top level JFreeChart object
chartEF = new JFreeChart(combinedData, overlaidPlot, "", JFreeChart.DEFAULT_TITLE_FONT, false);

JFreeChartFrame frame = new JFreeChartFrame("Sample", chartEF);
frame.setSize(400, 200);

Dimension sd = Toolkit.getDefaultToolkit().getScreenSize();
Dimension dd = frame.getSize();
frame.setLocation(sd.width / 2 - dd.width / 2, sd.height / 2 - dd.height / 2);

frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

frame.show();



}
catch (Exception e) {
e.printStackTrace();
}

}

}

David Gilbert

Re: Strange grid behavior at overlaid chart

Post by David Gilbert » Wed Apr 17, 2002 3:37 pm

Hi Dmitry,

Thanks for the code. I've run it and it does reproduce the problem...now I'll have to try to figure out why!

Regards,

DG.

David Gilbert

Re: Strange grid behavior at overlaid chart

Post by David Gilbert » Mon Apr 22, 2002 4:59 pm

My approach to solving this problem is to reorganise the code so that only the overlaid plot maintains axes, all the subplots have null axes. This is working OK for the overlaid plot but I need to do some more work to get the horizontally and vertically combined plots working the same way. This is quite a big change to the code (which was contributed to the project by Bill Kelemen) so I want to do some more testing before I commit anything to CVS...but I thought I'd let you know that I am still working on it.

Regards,

DG.

Dmitry Bessonov

Re: Strange grid behavior at overlaid chart

Post by Dmitry Bessonov » Mon Apr 22, 2002 5:29 pm

Hi Gilbert,

Many thanks for your activity.

Dmitry.

Edward Pottasch

Re: Strange grid behavior at overlaid chart

Post by Edward Pottasch » Sat May 04, 2002 1:10 pm

hi,

I have the same problem with these grid lines. I understand that this is under investigation.

I have another question though. These symbols in your plot, Dimitri, you add by using a Class DataPointDataset (which is not part of this package). How does one add symbols within JFreeChart. I only found the XYItemRenderer does something in that direction but it is very hard for me to find out how to add symbols and how to choose from a symbol set,

thanks,

regards, Edward

Dmitry Bessonov

Re: Strange grid behavior at overlaid chart

Post by Dmitry Bessonov » Sat May 04, 2002 2:36 pm

Hi, Edward

Class DataPointDataset extends AbstractSeriesDataset and implements XYDataset.
It's my custom dataset.
To create your own symbols representing data at the chart you should write a renderer class implementing XYItemRenderer and call .setXYItemRenderer(argument - your new renderer) of the plot object of your chart.
Look at StandardXYItemRenderer - it has enough comments inside.

Dmitry.

Edward Pottasch

Re: Strange grid behavior at overlaid chart

Post by Edward Pottasch » Sat May 04, 2002 4:24 pm

thnx for the tip,

Edward

Locked