Search in sources :

Example 71 with JFreeChart

use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.

the class DefaultChartService method getStackedAreaChart.

private JFreeChart getStackedAreaChart(BaseChart chart, CategoryDataset dataSet) {
    JFreeChart stackedAreaChart = ChartFactory.createStackedAreaChart(chart.getName(), chart.getDomainAxisLabel(), chart.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, !chart.isHideLegend(), false, false);
    setBasicConfig(stackedAreaChart, chart);
    CategoryPlot plot = (CategoryPlot) stackedAreaChart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRenderer(getStackedAreaRenderer());
    CategoryAxis xAxis = plot.getDomainAxis();
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    xAxis.setLabelFont(LABEL_FONT);
    return stackedAreaChart;
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) JFreeChart(org.jfree.chart.JFreeChart)

Example 72 with JFreeChart

use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.

the class DefaultChartService method getGaugeChart.

private JFreeChart getGaugeChart(BaseChart chart, ValueDataset dataSet) {
    MeterPlot meterPlot = new MeterPlot(dataSet);
    meterPlot.setUnits("");
    meterPlot.setRange(new Range(0.0d, 100d));
    for (int i = 0; i < 10; i++) {
        double start = i * 10;
        double end = start + 10;
        String label = String.valueOf(start);
        meterPlot.addInterval(new MeterInterval(label, new Range(start, end), COLOR_LIGHT_GRAY, null, COLOR_LIGHT_GRAY));
    }
    meterPlot.setMeterAngle(180);
    meterPlot.setDialBackgroundPaint(COLOR_LIGHT_GRAY);
    meterPlot.setDialShape(DialShape.CHORD);
    meterPlot.setNeedlePaint(COLORS[0]);
    meterPlot.setTickLabelsVisible(true);
    meterPlot.setTickLabelFont(LABEL_FONT);
    meterPlot.setTickLabelPaint(Color.BLACK);
    meterPlot.setTickPaint(COLOR_LIGHTER_GRAY);
    meterPlot.setValueFont(TITLE_FONT);
    meterPlot.setValuePaint(Color.BLACK);
    JFreeChart meterChart = new JFreeChart(chart.getName(), meterPlot);
    setBasicConfig(meterChart, chart);
    meterChart.removeLegend();
    return meterChart;
}
Also used : Range(org.jfree.data.Range) JFreeChart(org.jfree.chart.JFreeChart)

Example 73 with JFreeChart

use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.

the class DefaultChartService method getJFreeChart.

/**
     * Returns a JFreeChart of type defined in the chart argument.
     */
private JFreeChart getJFreeChart(BaseChart chart) {
    final CategoryDataset[] dataSets = getCategoryDataSet(chart);
    final CategoryDataset dataSet = dataSets[0];
    final BarRenderer barRenderer = getBarRenderer();
    final LineAndShapeRenderer lineRenderer = getLineRenderer();
    // ---------------------------------------------------------------------
    // Plot
    // ---------------------------------------------------------------------
    CategoryPlot plot = null;
    if (chart.isType(ChartType.LINE)) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), lineRenderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
    } else if (chart.isType(ChartType.COLUMN)) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
    } else if (chart.isType(ChartType.BAR)) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
        plot.setOrientation(PlotOrientation.HORIZONTAL);
    } else if (chart.isType(ChartType.AREA)) {
        return getStackedAreaChart(chart, dataSet);
    } else if (chart.isType(ChartType.PIE)) {
        return getMultiplePieChart(chart, dataSets);
    } else if (chart.isType(ChartType.STACKED_COLUMN)) {
        return getStackedBarChart(chart, dataSet, false);
    } else if (chart.isType(ChartType.STACKED_BAR)) {
        return getStackedBarChart(chart, dataSet, true);
    } else if (chart.isType(ChartType.RADAR)) {
        return getRadarChart(chart, dataSet);
    } else if (chart.isType(ChartType.GAUGE)) {
        Number number = dataSet.getValue(0, 0);
        ValueDataset valueDataSet = new DefaultValueDataset(number);
        return getGaugeChart(chart, valueDataSet);
    } else {
        throw new IllegalArgumentException("Illegal or no chart type: " + chart.getType());
    }
    if (chart.isRegression()) {
        plot.setDataset(1, dataSets[1]);
        plot.setRenderer(1, lineRenderer);
    }
    JFreeChart jFreeChart = new JFreeChart(chart.getName(), TITLE_FONT, plot, !chart.isHideLegend());
    setBasicConfig(jFreeChart, chart);
    if (chart.isTargetLine()) {
        plot.addRangeMarker(getMarker(chart.getTargetLineValue(), chart.getTargetLineLabel()));
    }
    if (chart.isBaseLine()) {
        plot.addRangeMarker(getMarker(chart.getBaseLineValue(), chart.getBaseLineLabel()));
    }
    if (chart.isHideSubtitle()) {
        jFreeChart.addSubtitle(getSubTitle(chart));
    }
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    // ---------------------------------------------------------------------
    // Category label positions
    // ---------------------------------------------------------------------
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLabel(chart.getDomainAxisLabel());
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setLabel(chart.getRangeAxisLabel());
    return jFreeChart;
}
Also used : DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) NumberAxis(org.jfree.chart.axis.NumberAxis) ValueDataset(org.jfree.data.general.ValueDataset) DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) JFreeChart(org.jfree.chart.JFreeChart) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) ValueAxis(org.jfree.chart.axis.ValueAxis)

Example 74 with JFreeChart

use of org.jfree.chart.JFreeChart in project uncommons-maths by dwdyer.

the class GraphPanel method generateGraph.

public void generateGraph(String title, Map<Double, Double> observedValues, Map<Double, Double> expectedValues, double expectedMean, double expectedStandardDeviation, boolean discrete) {
    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries observedSeries = new XYSeries("Observed");
    dataSet.addSeries(observedSeries);
    XYSeries expectedSeries = new XYSeries("Expected");
    dataSet.addSeries(expectedSeries);
    for (Map.Entry<Double, Double> entry : observedValues.entrySet()) {
        observedSeries.add(entry.getKey(), entry.getValue());
    }
    for (Map.Entry<Double, Double> entry : expectedValues.entrySet()) {
        expectedSeries.add(entry.getKey(), entry.getValue());
    }
    JFreeChart chart = ChartFactory.createXYLineChart(title, "Value", "Probability", dataSet, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    if (discrete) {
        // Render markers at each data point (these discrete points are the
        // distibution, not the lines between them).
        plot.setRenderer(new XYLineAndShapeRenderer());
    } else {
        // Render smooth lines between points for a continuous distribution.
        XYSplineRenderer renderer = new XYSplineRenderer();
        renderer.setBaseShapesVisible(false);
        plot.setRenderer(renderer);
    }
    chartPanel.setChart(chart);
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) XYPlot(org.jfree.chart.plot.XYPlot) XYSplineRenderer(org.jfree.chart.renderer.xy.XYSplineRenderer) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) Map(java.util.Map) JFreeChart(org.jfree.chart.JFreeChart)

Example 75 with JFreeChart

use of org.jfree.chart.JFreeChart in project processdash by dtuma.

the class AbstractEVTimeSeriesChart method createEVReportChart.

/**
     * Temporary method used by EVReport to build a chart
     */
public static JFreeChart createEVReportChart(XYDataset data) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, data, true, true, false);
    RangeXYItemRenderer renderer = new RangeXYItemRenderer();
    renderer.putAllSeriesPaints(SERIES_PAINTS);
    renderer.putAllSeriesStrokes(SERIES_STROKES);
    renderer.setLegendItemLabelGenerator(new SeriesNameGenerator());
    renderer.setBaseToolTipGenerator(new EVTimeSeriesTooltipGenerator());
    chart.getXYPlot().setRenderer(renderer);
    return chart;
}
Also used : JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)178 XYPlot (org.jfree.chart.plot.XYPlot)40 NumberAxis (org.jfree.chart.axis.NumberAxis)26 Color (java.awt.Color)22 DateAxis (org.jfree.chart.axis.DateAxis)21 DecimalFormat (java.text.DecimalFormat)18 ChartPanel (org.jfree.chart.ChartPanel)17 XYSeries (org.jfree.data.xy.XYSeries)17 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)17 RectangleInsets (org.jfree.ui.RectangleInsets)17 NumberFormat (java.text.NumberFormat)16 CategoryAxis (org.jfree.chart.axis.CategoryAxis)16 CategoryPlot (org.jfree.chart.plot.CategoryPlot)16 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)13 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)13 HashMap (java.util.HashMap)12 ValueAxis (org.jfree.chart.axis.ValueAxis)12 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)11 CategoryDataset (org.jfree.data.category.CategoryDataset)11 Paint (java.awt.Paint)10