# Jfreechart zwei charts



## Guest (6. Mai 2008)

Hallo,
ich versuche hier zwei charts in einer Darstellung darzustellen, aber irgendwie klappt es nicht, kann mir jemand helfen, oder wird es gar nicht gehen?!

Hier ist der erste Quellcode vom BarChart:


```
package org.jfree.chart.demo;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.XYSeries;
import org.jfree.data.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
 * This demo shows a simple bar chart created using the {@link XYSeriesCollection} dataset.
 *
 * @author David Gilbert
 */
public class XYSeriesDemo3 extends ApplicationFrame {

    /**
     * Creates a new demo instance.
     *
     * @param title  the frame title.
     */
    public XYSeriesDemo3(String title) {

        super(title);
        XYSeries series = new XYSeries("Random Data");
        series.add(1.0, 500.2);
        series.add(5.0, 694.1);
        series.add(4.0, 100.0);
        series.add(12.5, 734.4);
        series.add(17.3, 453.2);
        series.add(21.2, 500.2);
        series.add(21.9, null);
        series.add(25.6, 734.4);
        series.add(30.0, 453.2);
        XYSeriesCollection data = new XYSeriesCollection(series);
        JFreeChart chart = ChartFactory.createXYBarChart(
            "XY Series Demo",
            "X", 
            false,
            "Y", 
            data,
            PlotOrientation.VERTICAL,
            true,
            true,
            false
        );
        
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    }

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * [url]http://www.object-refinery.com/jfreechart/guide.html[/url]                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************
    
    /**
     * Starting point for the demonstration application.
     *
     * @param args  ignored.
     */
    public static void main(String[] args) {

        XYSeriesDemo3 demo = new XYSeriesDemo3("XY Series Demo 3");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);

    }

}
```


Nun versuche ich in diesem BarChart noch ein Linienchart einzuzeichnen:

```
package org.jfree.chart.demo;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.XYSeries;
import org.jfree.data.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
 * Demo for {@link XYSeries}, where all the y values are the same.
 *
 * @author David Gilbert
 */
public class XYSeriesDemo2 extends ApplicationFrame {

    /**
     * A demonstration application showing an {@link XYSeries} where all the y-values are the same.
     *
     * @param title  the frame title.
     */
    public XYSeriesDemo2(String title) {

        super(title);
        XYSeries series = new XYSeries("Flat Data");
        series.add(1.0, 100.0);
        series.add(5.0, 100.0);
        series.add(4.0, 100.0);
        series.add(12.5, 100.0);
        series.add(17.3, 100.0);
        series.add(21.2, 100.0);
        series.add(21.9, 100.0);
        series.add(25.6, 100.0);
        series.add(30.0, 100.0);
        XYSeriesCollection data = new XYSeriesCollection(series);
        JFreeChart chart = ChartFactory.createXYLineChart(
            "XY Series Demo 2",
            "X", 
            "Y", 
            data,
            PlotOrientation.VERTICAL,
            true,
            true,
            false
        );

        XYPlot plot = (XYPlot) chart.getPlot();
        NumberAxis axis = (NumberAxis) plot.getRangeAxis();
        axis.setAutoRangeIncludesZero(false);
        axis.setAutoRangeMinimumSize(1.0);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    }

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * [url]http://www.object-refinery.com/jfreechart/guide.html[/url]                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************
    
    /**
     * Starting point for the demonstration application.
     *
     * @param args  ignored.
     */
    public static void main(String[] args) {

        XYSeriesDemo2 demo = new XYSeriesDemo2("XY Series Demo 2");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);

    }

}
```

Ich weiß nicht, ob dieses überhaupt machbar ist, aber wenn ja, helft mir bitte weiter?!
Gruss


----------



## Guest (6. Mai 2008)

schau dir mal die ganzen Beispiele an, da ist sicher was dabei, bei den jfreechart- Teilen funktionierts das auf jeden Fall


----------



## LukeVlbg (21. Jul 2009)

Klar ist das möglich.

Folgender Link sollte deine Fragen beantworten:
JFreeChart: Overlaid Bar Chart Demo : Overlaid Bar ChartChartJava

gruß


----------

