Hello,
I hope I have an elementary question.
I want to create an combined chart with Income and Expense series.
Vertical axis means money.
Horizontal axis means weeks.
I have no problem with it, I even have a balance chart (ChartFactory.createCombinableTimeSeriesChart) in it - see source below.
Well, finally my question: Is it possible to have a CategoryAxis as Horizontal axis (City - Incomes and Expenses on cities) ?
This source:
CategoryAxis cityAxis = new HorizontalCategoryAxis("City");
NumberAxis valueAxis = new VerticalNumberAxis("Finance");
CombinedPlot overlaidPlot = new CombinedPlot(cityAxis, valueAxis);
does not work, I receive:
com.jrefinery.chart.PlotNotCompatibleException: Axis.setPlot(...): plot not compatible with axis.
Well, maybe I am totally wrong so I have better question:
How should I create a chart [
Vertical axis means money.
Horizontal axis means cities (an enumeration)
Income and Expense series]
in one picture ?
Thank you.
Michal.
import java.awt.*;
import com.jrefinery.chart.*;
import com.jrefinery.ui.*;
import com.jrefinery.data.*;
import com.jrefinery.chart.combination.*;
public class TestGraph3 extends ApplicationFrame {
public static void main(String[] args) {
TestGraph3 demo = new TestGraph3();
demo.pack();
demo.setVisible(true);
}
public TestGraph3() {
JFreeChart chart = createCombinedChart();
JFreeChartPanel panel = new JFreeChartPanel(chart, true, true, true, false, true);
this.setContentPane(panel);
}
private JFreeChart createCombinedChart() {
double[] incomeData = new double[] {3.75, 2, 1.78, 0.3};
double[] expenseData = new double[] {1, 3.56, 0, 2.3};
BasicTimeSeries incomeSerie = new BasicTimeSeries("Income", Week.class);
BasicTimeSeries expenseSerie = new BasicTimeSeries("Expense", Week.class);
BasicTimeSeries balanceSerie = new BasicTimeSeries("Balance", Week.class);
double previous = 0;
for (int i = 0; i < 4; i++) {
incomeSerie.add(new Week(i, 2002), new Double(incomeData));
expenseSerie.add(new Week(i, 2002), new Double(-expenseData));
previous += incomeData - expenseData;
balanceSerie.add(new Week(i, 2002), new Double(previous));
}
CombinedDataset dataset = new CombinedDataset();
dataset.add(new TimeSeriesCollection(incomeSerie));
dataset.add(new TimeSeriesCollection(expenseSerie));
dataset.add(new TimeSeriesCollection(balanceSerie));
ValueAxis timeAxis = new HorizontalDateAxis("Date");
timeAxis.setCrosshairVisible(false);
NumberAxis valueAxis = new VerticalNumberAxis("Finance");
CombinedPlot overlaidPlot = new CombinedPlot(timeAxis, valueAxis);
XYPlot plot0 = new XYPlot(timeAxis, valueAxis, new VerticalXYBarRenderer(0.20));
SeriesDataset s0 = new SubSeriesDataset(dataset, 0);
CombinedChart c0 = ChartFactory.createCombinableChart(s0, plot0);
overlaidPlot.add(c0);
XYPlot plot1 = new XYPlot(timeAxis, valueAxis, new VerticalXYBarRenderer(0.20));
SeriesDataset s1 = new SubSeriesDataset(dataset, 1);
CombinedChart c1 = ChartFactory.createCombinableChart(s1, plot1);
overlaidPlot.add(c1);
SeriesDataset s2 = new SubSeriesDataset(dataset, 2);
CombinedChart c2 = ChartFactory.createCombinableTimeSeriesChart(timeAxis, valueAxis, s2);
overlaidPlot.add(c2);
overlaidPlot.setSeriesPaint(new Paint[] { Color.blue, Color.magenta, Color.black });
overlaidPlot.setSeriesStroke(new Stroke[] {new BasicStroke(5)});
return new JFreeChart(dataset, overlaidPlot,
"CashFlow example", JFreeChart.DEFAULT_TITLE_FONT, true);
}
}
CombinedPlot and CategoryAxis
Re: CombinedPlot and CategoryAxis
Hi Michal,
You cannot combine category plots in 0.8.1. The next release will have this feature...you can check out the code from CVS on SourceForge.
Regards,
DG.
You cannot combine category plots in 0.8.1. The next release will have this feature...you can check out the code from CVS on SourceForge.
Regards,
DG.
Re: CombinedPlot and CategoryAxis
Hi Dave,
Is this true for release 0.9.0 too?
If not, then where does com.jrefinery.chart.combination.* lie?
Thanks
Is this true for release 0.9.0 too?
If not, then where does com.jrefinery.chart.combination.* lie?
Thanks
Re: CombinedPlot and CategoryAxis
The combined charts were reorganised in 0.9.0. Now you can just use the following classes in the com.jrefinery.chart package:
CombinedXYPlot
OverlaidXYPlot
OverlaidVerticalCategoryPlot
There's a demo for each in the com.jrefinery.chart.demo package.
Regards,
DG.
CombinedXYPlot
OverlaidXYPlot
OverlaidVerticalCategoryPlot
There's a demo for each in the com.jrefinery.chart.demo package.
Regards,
DG.
Re: CombinedPlot and CategoryAxis
With version 0.9.0 is it possible to construct a Vertically Combined Chart with a category axis as the Horizontal axis. I do not wish to construct a overlaid combined chart.
Regards,
Kieran
Regards,
Kieran