Search in sources :

Example 26 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project zaproxy by zaproxy.

the class ScanProgressDialog method createChart.

private JFreeChart createChart(final XYDataset dataset) {
    JFreeChart result = ChartFactory.createTimeSeriesChart(// No title - it just takes up space
    null, Constant.messages.getString("ascan.progress.chart.time"), Constant.messages.getString("ascan.progress.chart.responses"), dataset, true, true, false);
    XYPlot plot = result.getXYPlot();
    ValueAxis daxis = plot.getDomainAxis();
    daxis.setAutoRange(true);
    daxis.setAutoRangeMinimumSize(60000.0);
    plot.getRangeAxis().setAutoRangeMinimumSize(20);
    return result;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) JFreeChart(org.jfree.chart.JFreeChart)

Example 27 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 28 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(PlotData plotData) {
    final CategoryDataset[] dataSets = getCategoryDataSet(plotData);
    final CategoryDataset dataSet = dataSets[0];
    final BarRenderer barRenderer = getBarRenderer();
    final LineAndShapeRenderer lineRenderer = getLineRenderer();
    // ---------------------------------------------------------------------
    // Plot
    // ---------------------------------------------------------------------
    CategoryPlot plot;
    if (plotData.isType(VisualizationType.LINE.name())) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), lineRenderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
    } else if (plotData.isType(VisualizationType.COLUMN.name())) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
    } else if (plotData.isType(VisualizationType.BAR.name())) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
        plot.setOrientation(PlotOrientation.HORIZONTAL);
    } else if (plotData.isType(VisualizationType.AREA.name())) {
        return getStackedAreaChart(plotData, dataSet);
    } else if (plotData.isType(VisualizationType.PIE.name())) {
        return getMultiplePieChart(plotData, dataSets);
    } else if (plotData.isType(VisualizationType.STACKED_COLUMN.name())) {
        return getStackedBarChart(plotData, dataSet, false);
    } else if (plotData.isType(VisualizationType.STACKED_BAR.name())) {
        return getStackedBarChart(plotData, dataSet, true);
    } else if (plotData.isType(VisualizationType.RADAR.name())) {
        return getRadarChart(plotData, dataSet);
    } else if (plotData.isType(VisualizationType.GAUGE.name())) {
        Number number = dataSet.getValue(0, 0);
        ValueDataset valueDataSet = new DefaultValueDataset(number);
        return getGaugeChart(plotData, valueDataSet);
    } else {
        throw new IllegalArgumentException("Illegal or no chart type: " + plotData.getType());
    }
    if (plotData.isRegression()) {
        plot.setDataset(1, dataSets[1]);
        plot.setRenderer(1, lineRenderer);
    }
    JFreeChart jFreeChart = new JFreeChart(plotData.getName(), TITLE_FONT, plot, !plotData.isHideLegend());
    setBasicConfig(jFreeChart, plotData);
    if (plotData.isTargetLine()) {
        plot.addRangeMarker(getMarker(plotData.getTargetLineValue(), plotData.getTargetLineLabel()));
    }
    if (plotData.isBaseLine()) {
        plot.addRangeMarker(getMarker(plotData.getBaseLineValue(), plotData.getBaseLineLabel()));
    }
    if (plotData.isHideSubtitle()) {
        jFreeChart.addSubtitle(getSubTitle(plotData));
    }
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    // ---------------------------------------------------------------------
    // Category label positions
    // ---------------------------------------------------------------------
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLabel(plotData.getDomainAxisLabel());
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setLabel(plotData.getRangeAxisLabel());
    return jFreeChart;
}
Also used : DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) ValueDataset(org.jfree.data.general.ValueDataset) DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot) 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 29 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project GT by Tencent.

the class CPURealTimeChart method createChart.

@Override
public JFreeChart createChart() {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("CPU实时曲线图", "时间", "CPU%", dataset, true, true, false);
    // 设置,不然中文会存在乱码
    chart.getTitle().setFont(new Font("宋体", Font.BOLD, 20));
    XYPlot xyPlot = (XYPlot) chart.getXYPlot();
    ValueAxis domainAxis = xyPlot.getDomainAxis();
    ValueAxis rangeAxis = xyPlot.getRangeAxis();
    domainAxis.setLabelFont(new Font("宋体", Font.BOLD, 14));
    domainAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 12));
    rangeAxis.setLabelFont(new Font("宋体", Font.BOLD, 14));
    rangeAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 12));
    return chart;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font)

Example 30 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project n2a by frothga.

the class Plot method updateChart.

public void updateChart(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();
    plot.setNotify(false);
    updateDatasets();
    LegendTitle legend = chart.getLegend();
    legend.setVisible(columnCount <= 10);
    NumberAxis axis0 = (NumberAxis) plot.getRangeAxis();
    axis0.setAutoRangeIncludesZero(false);
    if (range0 > 0)
        axis0.setAutoRangeMinimumSize(range0 / 2);
    else
        axis0.setAutoRangeMinimumSize(1);
    // range locked
    if (!Double.isNaN(ymin))
        axis0.setRange(ymin, ymax);
    if (!Double.isNaN(xmin)) {
        ValueAxis x = plot.getDomainAxis();
        x.setRange(xmin, xmax);
    }
    int count = dataset0.getSeriesCount();
    float shift = 0;
    if (dataset1 != null) {
        // So we use only half of the color range
        count *= 2;
        shift = 0.75f + 0.5f / count;
    }
    XYLineAndShapeRenderer renderer;
    XYItemRenderer ir = plot.getRenderer();
    if (ir instanceof XYLineAndShapeRenderer) {
        renderer = (XYLineAndShapeRenderer) ir;
    } else {
        renderer = new XYLineAndShapeRenderer();
        plot.setRenderer(renderer);
    }
    for (int i = 0; i < dataset0.getSeriesCount(); i++) {
        Column column = left.get(i);
        // does not fire renderer change event
        styleSeries(renderer, i, column, count, shift);
    }
    // fires renderer change event
    renderer.setDrawSeriesLineAsPath(true);
    if (dataset1 == null) {
        axis0.setTickMarkPaint(Color.black);
        axis0.setTickLabelPaint(Color.black);
        axis0.setAxisLinePaint(Color.black);
        plot.setDataset(1, null);
        plot.setRangeAxis(1, null);
        plot.setRenderer(1, null);
    } else {
        Color color0 = Color.getHSBColor(0.0f, 1.0f, 0.8f);
        axis0.setTickMarkPaint(color0);
        axis0.setTickLabelPaint(color0);
        axis0.setAxisLinePaint(color0);
        plot.setDataset(1, dataset1);
        plot.mapDatasetToRangeAxis(1, 1);
        NumberAxis axis1 = (NumberAxis) plot.getRangeAxis(1);
        if (axis1 == null) {
            axis1 = new NumberAxis();
            axis1.setAutoRangeIncludesZero(false);
            axis1.setTickLabelFont(axis0.getTickLabelFont());
            Color color1 = Color.getHSBColor(0.5f, 1.0f, 0.8f);
            axis1.setTickMarkPaint(color1);
            axis1.setTickLabelPaint(color1);
            axis1.setAxisLinePaint(color1);
            plot.setRangeAxis(1, axis1);
        }
        // else we created axis1, so all the initial settings are correct
        if (range1 > 0)
            axis1.setAutoRangeMinimumSize(range1 / 2);
        else
            axis1.setAutoRangeMinimumSize(1);
        count = dataset1.getSeriesCount() * 2;
        shift = 0.25f + 0.5f / count;
        ir = plot.getRenderer(1);
        if (ir instanceof XYLineAndShapeRenderer) {
            renderer = (XYLineAndShapeRenderer) ir;
        } else {
            renderer = new XYLineAndShapeRenderer();
            plot.setRenderer(1, renderer);
        }
        for (int i = 0; i < dataset1.getSeriesCount(); i++) {
            Column column = right.get(i);
            styleSeries(renderer, i, column, count, shift);
        }
        renderer.setDrawSeriesLineAsPath(true);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    }
    plot.setNotify(true);
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) LegendTitle(org.jfree.chart.title.LegendTitle) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer)

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