Example usage for org.jfree.chart.axis NumberAxis setFixedDimension

List of usage examples for org.jfree.chart.axis NumberAxis setFixedDimension

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis setFixedDimension.

Prototype

public void setFixedDimension(double dimension) 

Source Link

Document

Sets the fixed dimension for the axis.

Usage

From source file:org.encog.workbench.dialogs.training.ChartPane.java

/**
 * Create the initial chart./*from   w ww .jav  a  2  s.  c  om*/
 * @return The chart.
 */
private JFreeChart createChart() {

    this.chart = ChartFactory.createXYLineChart(null, "Iteration", "Current Error", this.dataset1,
            PlotOrientation.VERTICAL, true, true, false);

    final XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);

    plot.getRangeAxis().setFixedDimension(15.0);

    // AXIS 2
    final NumberAxis axis2 = new NumberAxis("Error Improvement");
    axis2.setFixedDimension(10.0);
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    plot.setDataset(1, this.dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    ChartUtilities.applyCurrentTheme(this.chart);

    return this.chart;
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortCounterPlotWorker.java

@Override
protected Void doInBackground() throws Exception {
    // 1.  counter value (already done, just add following to this)
    // 2.  delta/period
    ////from w  w  w.jav a 2s  . com
    //    -- if error counter --
    // 3.  include xmit and rcv traffic deltas? (own scale)
    //
    //
    //    -- if traffic counter --
    // 3.  include rate and utilization values?
    //

    // this is a SwingWorker thread from its pool, give it a recognizable name
    Thread.currentThread().setName("PortCounterPlotWorker");

    logger.info("Worker Building Plot");
    SMT_UpdateService updateService = SMT_UpdateService.getInstance();
    OMS_Collection history = updateService.getCollection();
    OSM_FabricDeltaCollection deltaHistory = history.getOSM_FabricDeltaCollection();

    XYPlot plot = (XYPlot) Chart.getPlot();

    // AXIS 2 - the change, or delta value of the desired counter
    NumberAxis axis2 = new NumberAxis(PortCounterAxisLabel.DELTA.getName());
    axis2.setFixedDimension(10.0);
    axis2.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, axis2);

    XYDataset dataset2 = createDeltaDataset(deltaHistory, PortCounter, PortCounterAxisLabel.DELTA.getName());
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    plot.setRenderer(1, renderer2);

    // the other two axis are optional, and vary depending on the
    // type of counter
    NumberAxis axis3 = null;
    XYDataset dataset3 = null;
    XYItemRenderer renderer3 = null;
    NumberAxis axis4 = null;
    XYDataset dataset4 = null;
    XYItemRenderer renderer4 = null;

    if (AddExtra) {
        if (isError) {

            // add rcv deltas
            PortCounterName pcr = PortCounterName.rcv_data;
            axis3 = new NumberAxis(PortCounterAxisLabel.RCV_DELTA.getName());
            axis3.setFixedDimension(10.0);
            axis3.setAutoRangeIncludesZero(false);
            plot.setRangeAxis(2, axis3);

            dataset3 = createDeltaDataset(deltaHistory, pcr, pcr.getName());
            plot.setDataset(2, dataset3);
            plot.mapDatasetToRangeAxis(2, 2);
            renderer3 = new StandardXYItemRenderer();
            plot.setRenderer(2, renderer3);

            // add xmit deltas
            pcr = PortCounterName.xmit_data;
            axis4 = new NumberAxis(PortCounterAxisLabel.XMT_DELTA.getName());
            axis4.setFixedDimension(10.0);
            axis4.setAutoRangeIncludesZero(false);
            plot.setRangeAxis(3, axis4);

            dataset4 = createDeltaDataset(deltaHistory, pcr, pcr.getName());
            plot.setDataset(3, dataset4);
            plot.mapDatasetToRangeAxis(3, 3);
            renderer4 = new StandardXYItemRenderer();
            plot.setRenderer(3, renderer4);

            // use a common scale for both xmit and rcv counters
            double minRange = axis3.getLowerBound() < axis4.getLowerBound() ? axis3.getLowerBound()
                    : axis4.getLowerBound();
            double maxRange = axis3.getUpperBound() < axis4.getUpperBound() ? axis4.getUpperBound()
                    : axis3.getUpperBound();
            axis3.setAutoRange(false);
            axis4.setAutoRange(false);
            axis3.setRange(minRange, maxRange);
            axis4.setRange(minRange, maxRange);
        } else {
            // add rate
            PortCounterName pcr = PortCounter;
            axis3 = new NumberAxis(pcr.getName() + " " + PortCounterAxisLabel.RATE.getUnits());
            axis3.setFixedDimension(10.0);
            axis3.setAutoRangeIncludesZero(true);
            plot.setRangeAxis(2, axis3);

            dataset3 = createRateDataset(deltaHistory, pcr, PortCounterAxisLabel.RATE.getName());
            plot.setDataset(2, dataset3);
            plot.mapDatasetToRangeAxis(2, 2);
            renderer3 = new StandardXYItemRenderer();
            plot.setRenderer(2, renderer3);

            // add utilization
            axis4 = new NumberAxis(pcr.getName() + " " + PortCounterAxisLabel.UTILIZATION.getUnits());
            axis4.setFixedDimension(10.0);
            //         axis4.setAutoRangeIncludesZero(true);
            axis4.setRange(0.0, 100.0);
            plot.setRangeAxis(3, axis4);

            dataset4 = createUtilizationDataset(deltaHistory, pcr, PortCounterAxisLabel.UTILIZATION.getName());
            plot.setDataset(3, dataset4);
            plot.mapDatasetToRangeAxis(3, 3);
            renderer4 = new StandardXYItemRenderer();
            plot.setRenderer(3, renderer4);
        }
    }
    ChartUtilities.applyCurrentTheme(Chart);

    Color c1 = Color.black;
    Color c2 = Color.blue;

    Color c3 = Color.green;
    Color c4 = Color.magenta;

    Color ce = Color.red;

    if (isError)
        c2 = ce;

    // change the series and axis colours after the theme has
    // been applied...
    plot.getRenderer().setSeriesPaint(0, c1);

    renderer2.setSeriesPaint(0, c2);
    axis2.setLabelPaint(c2);
    axis2.setTickLabelPaint(c2);

    if (AddExtra) {
        renderer3.setSeriesPaint(0, c3);
        axis3.setLabelPaint(c3);
        axis3.setTickLabelPaint(c3);

        renderer4.setSeriesPaint(0, c4);
        axis4.setLabelPaint(c4);
        axis4.setTickLabelPaint(c4);
    }

    return null;
}

From source file:dk.netarkivet.harvester.harvesting.monitor.StartedJobHistoryChartGen.java

/**
 * Generates a chart in PNG format./*from   w  w  w .j  ava 2  s. c o  m*/
 * @param outputFile the output file, it should exist.
 * @param pxWidth the image width in pixels.
 * @param pxHeight the image height in pixels.
 * @param chartTitle the chart title, may be null.
 * @param xAxisTitle the x axis title
 * @param yDataSeriesRange the axis range (null for auto)
 * @param yDataSeriesTitles the Y axis titles.
 * @param timeValuesInSeconds the time values in seconds
 * @param yDataSeries the Y axis value series.
 * @param yDataSeriesColors the Y axis value series drawing colors.
 * @param yDataSeriesTickSuffix TODO explain argument yDataSeriesTickSuffix
 * @param drawBorder draw, or not, the border.
 * @param backgroundColor the chart background color.
 */
final void generatePngChart(File outputFile, int pxWidth, int pxHeight, String chartTitle, String xAxisTitle,
        String[] yDataSeriesTitles, double[] timeValuesInSeconds, double[][] yDataSeriesRange,
        double[][] yDataSeries, Color[] yDataSeriesColors, String[] yDataSeriesTickSuffix, boolean drawBorder,
        Color backgroundColor) {

    // Domain axis
    NumberAxis xAxis = new NumberAxis(xAxisTitle);
    xAxis.setFixedDimension(CHART_AXIS_DIMENSION);
    xAxis.setLabelPaint(Color.black);
    xAxis.setTickLabelPaint(Color.black);

    double maxSeconds = getMaxValue(timeValuesInSeconds);
    TimeAxisResolution xAxisRes = TimeAxisResolution.findTimeUnit(maxSeconds);
    xAxis.setTickUnit(new NumberTickUnit(xAxisRes.tickStep));
    double[] scaledTimeValues = xAxisRes.scale(timeValuesInSeconds);

    String tickSymbol = I18N.getString(locale, "running.job.details.chart.timeunit.symbol." + xAxisRes.name());
    xAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + tickSymbol + "'"));

    // First dataset
    String firstDataSetTitle = yDataSeriesTitles[0];
    XYDataset firstDataSet = createXYDataSet(firstDataSetTitle, scaledTimeValues, yDataSeries[0]);
    Color firstDataSetColor = yDataSeriesColors[0];

    // First range axis
    NumberAxis firstYAxis = new NumberAxis(firstDataSetTitle);

    firstYAxis.setFixedDimension(CHART_AXIS_DIMENSION);
    setAxisRange(firstYAxis, yDataSeriesRange[0]);
    firstYAxis.setLabelPaint(firstDataSetColor);
    firstYAxis.setTickLabelPaint(firstDataSetColor);
    String firstAxisTickSuffix = yDataSeriesTickSuffix[0];
    if (firstAxisTickSuffix != null && !firstAxisTickSuffix.isEmpty()) {
        firstYAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + firstAxisTickSuffix + "'"));
    }

    // Create the plot with domain axis and first range axis
    XYPlot plot = new XYPlot(firstDataSet, xAxis, firstYAxis, null);

    XYLineAndShapeRenderer firstRenderer = new XYLineAndShapeRenderer(true, false);
    plot.setRenderer(firstRenderer);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    firstRenderer.setSeriesPaint(0, firstDataSetColor);

    // Now iterate on next axes
    for (int i = 1; i < yDataSeries.length; i++) {
        // Create axis
        String seriesTitle = yDataSeriesTitles[i];
        Color seriesColor = yDataSeriesColors[i];
        NumberAxis yAxis = new NumberAxis(seriesTitle);

        yAxis.setFixedDimension(CHART_AXIS_DIMENSION);
        setAxisRange(yAxis, yDataSeriesRange[i]);

        yAxis.setLabelPaint(seriesColor);
        yAxis.setTickLabelPaint(seriesColor);

        String yAxisTickSuffix = yDataSeriesTickSuffix[i];
        if (yAxisTickSuffix != null && !yAxisTickSuffix.isEmpty()) {
            yAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + yAxisTickSuffix + "'"));
        }

        // Create dataset and add axis to plot
        plot.setRangeAxis(i, yAxis);
        plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_LEFT);
        plot.setDataset(i, createXYDataSet(seriesTitle, scaledTimeValues, yDataSeries[i]));
        plot.mapDatasetToRangeAxis(i, i);
        XYItemRenderer renderer = new StandardXYItemRenderer();
        renderer.setSeriesPaint(0, seriesColor);
        plot.setRenderer(i, renderer);
    }

    // Create the chart
    JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    // Customize rendering
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);

    // Render image
    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, pxWidth, pxHeight);
    } catch (IOException e) {
        LOG.error("Chart export failed", e);
    }
}