I have a curved graph, with several peaks, and I want to fill the integral area of some of the peaks
Example:
My first thought was to define one dataset for the graph. The peaks I would render by using a XYDifferenceRenderer and one dataset per peak.
My first example has two peaks, filling the area of one peak:
- Code: Select all
public class Test {
public static void main(String[] args) {
new Test();
}
/**
* Default Empty Constructor
*/
public Test() {
ValueAxis timeAxis = new NumberAxis("Time");
timeAxis.setLowerMargin(0.02);
timeAxis.setUpperMargin(0.02);
NumberAxis valueAxis = new NumberAxis("Value");
valueAxis.setAutoRangeIncludesZero(false);
XYPlot lPlot = new XYPlot(getXYDataSet_Values(), timeAxis, valueAxis, null);
lPlot.setRenderer(new DefaultXYItemRenderer());
lPlot.setDataset(1, getXYDataSet_FirstPeak());
lPlot.setRenderer(1, new XYDifferenceRenderer(
Color.green, Color.red, false));
JFreeChart freeChart = new JFreeChart("Trend",
JFreeChart.DEFAULT_TITLE_FONT, lPlot, true);
ChartPanel chartPanel_Ctrl = new ChartPanel(freeChart);
JFrame frame = new JFrame();
frame.getContentPane().add(chartPanel_Ctrl);
frame.pack();
frame.setVisible(true);
}
private XYDataset getXYDataSet_FirstPeak() {
DefaultXYDataset set = new DefaultXYDataset();
set.addSeries("Series2", new double[][] {
{
1, 2, 3
}, {
0, 1, 0
}
});
set.addSeries("series3", new double[][] {
{
1, 2, 3
}, {
0, 0, 0
}
});
return set;
}
private XYDataset getXYDataSet_Values() {
DefaultXYDataset set = new DefaultXYDataset();
set.addSeries("Series1", new double[][] {
{
0, 1, 2, 3, 4, 5, 6, 7
}, {
0, 0, 1, 0, 0, 1, 0, 0
}
});
return set;
}
}
The problem is, that I get the labels of series2 and series3 (the Peak area) in the Legend, which is not what I want. Any clever solution to this?
