Search in sources :

Example 1 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project series-rest-api by 52North.

the class ChartIoHandler method configureDomainAxis.

private void configureDomainAxis(XYPlot plot) {
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelFont(LabelConstants.FONT_LABEL);
    domainAxis.setLabelFont(LabelConstants.FONT_LABEL);
    domainAxis.setTickLabelPaint(LabelConstants.COLOR);
    domainAxis.setLabelPaint(LabelConstants.COLOR);
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis)

Example 2 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project libresonic by Libresonic.

the class StatusChartController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String type = request.getParameter("type");
    int index = Integer.parseInt(request.getParameter("index"));
    List<TransferStatus> statuses = Collections.emptyList();
    if ("stream".equals(type)) {
        statuses = statusService.getAllStreamStatuses();
    } else if ("download".equals(type)) {
        statuses = statusService.getAllDownloadStatuses();
    } else if ("upload".equals(type)) {
        statuses = statusService.getAllUploadStatuses();
    }
    if (index < 0 || index >= statuses.size()) {
        return null;
    }
    TransferStatus status = statuses.get(index);
    TimeSeries series = new TimeSeries("Kbps", Millisecond.class);
    TransferStatus.SampleHistory history = status.getHistory();
    long to = System.currentTimeMillis();
    long from = to - status.getHistoryLengthMillis();
    Range range = new DateRange(from, to);
    if (!history.isEmpty()) {
        TransferStatus.Sample previous = history.get(0);
        for (int i = 1; i < history.size(); i++) {
            TransferStatus.Sample sample = history.get(i);
            long elapsedTimeMilis = sample.getTimestamp() - previous.getTimestamp();
            long bytesStreamed = Math.max(0L, sample.getBytesTransfered() - previous.getBytesTransfered());
            double kbps = (8.0 * bytesStreamed / 1024.0) / (elapsedTimeMilis / 1000.0);
            series.addOrUpdate(new Millisecond(new Date(sample.getTimestamp())), kbps);
            previous = sample;
        }
    }
    // Compute moving average.
    series = MovingAverage.createMovingAverage(series, "Kbps", 20000, 5000);
    // Find min and max values.
    double min = 100;
    double max = 250;
    for (Object obj : series.getItems()) {
        TimeSeriesDataItem item = (TimeSeriesDataItem) obj;
        double value = item.getValue().doubleValue();
        if (item.getPeriod().getFirstMillisecond() > from) {
            min = Math.min(min, value);
            max = Math.max(max, value);
        }
    }
    // Add 10% to max value.
    max *= 1.1D;
    // Subtract 10% from min value.
    min *= 0.9D;
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    XYItemRenderer renderer = plot.getRendererForDataset(dataset);
    renderer.setSeriesPaint(0, Color.blue.darker());
    renderer.setSeriesStroke(0, new BasicStroke(2f));
    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);
    chart.setBackgroundPaint(bgColor);
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setRange(range);
    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setRange(new Range(min, max));
    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);
    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, IMAGE_HEIGHT);
    return null;
}
Also used : Range(org.jfree.data.Range) Date(java.util.Date) JFreeChart(org.jfree.chart.JFreeChart) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) TransferStatus(org.libresonic.player.domain.TransferStatus) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project jgnash by ccavanaugh.

the class SecurityHighLowChart method createHighLowChart.

private static JFreeChart createHighLowChart(String title, String timeAxisLabel, String valueAxisLabel, AbstractXYDataset data, boolean legend) {
    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());
    XYPlot plot = new XYPlot(data, timeAxis, valueAxis, renderer);
    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) HighLowItemLabelGenerator(org.jfree.chart.labels.HighLowItemLabelGenerator) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) HighLowRenderer(org.jfree.chart.renderer.xy.HighLowRenderer) JFreeChart(org.jfree.chart.JFreeChart)

Example 4 with ValueAxis

use of org.jfree.chart.axis.ValueAxis 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 5 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project processdash by dtuma.

the class CGIChartBase method setupCategoryChart.

protected void setupCategoryChart(JFreeChart chart) {
    if (!(chart.getPlot() instanceof CategoryPlot))
        return;
    CategoryPlot cp = chart.getCategoryPlot();
    CategoryAxis catAxis = cp.getDomainAxis();
    ValueAxis otherAxis = cp.getRangeAxis();
    if (!chromeless) {
        String catAxisLabel = data.getColName(0);
        if (catAxisLabel == null)
            catAxisLabel = Translator.translate("Project/Task");
        String otherAxisLabel = Translator.translate(getSetting("units"));
        if ((otherAxisLabel == null || otherAxisLabel.length() == 0) && data.numCols() == 1)
            otherAxisLabel = data.getColName(1);
        if (otherAxisLabel == null)
            otherAxisLabel = Translator.translate("Value");
        String catLabels = getParameter("categoryLabels");
        catAxis.setLabel(catAxisLabel);
        otherAxis.setLabel(otherAxisLabel);
        if ("vertical".equalsIgnoreCase(catLabels))
            catAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
        else if ("none".equalsIgnoreCase(catLabels))
            catAxis.setTickLabelsVisible(false);
    }
    if (data.numCols() == 1 && getParameter("noSkipLegend") == null) {
        chart.removeLegend();
        chart.getPlot().setInsets(new RectangleInsets(5, 2, 2, 5));
    }
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) RectangleInsets(org.jfree.ui.RectangleInsets) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Aggregations

ValueAxis (org.jfree.chart.axis.ValueAxis)182 XYPlot (org.jfree.chart.plot.XYPlot)52 NumberAxis (org.jfree.chart.axis.NumberAxis)44 JFreeChart (org.jfree.chart.JFreeChart)37 CategoryPlot (org.jfree.chart.plot.CategoryPlot)35 Paint (java.awt.Paint)31 CategoryAxis (org.jfree.chart.axis.CategoryAxis)30 Test (org.junit.Test)24 Rectangle2D (java.awt.geom.Rectangle2D)20 Iterator (java.util.Iterator)20 XYDataset (org.jfree.data.xy.XYDataset)20 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)18 Range (org.jfree.data.Range)18 CategoryDataset (org.jfree.data.category.CategoryDataset)17 RectangleEdge (org.jfree.ui.RectangleEdge)16 XYSeries (org.jfree.data.xy.XYSeries)14 Font (java.awt.Font)13 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)13 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)13 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)13