Example usage for org.jfree.chart.renderer.category LineAndShapeRenderer setSeriesPaint

List of usage examples for org.jfree.chart.renderer.category LineAndShapeRenderer setSeriesPaint

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category LineAndShapeRenderer setSeriesPaint.

Prototype

public void setSeriesPaint(int series, Paint paint) 

Source Link

Document

Sets the paint used for a series and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:hudson.util.ColorPalette.java

/**
 * Applies {@link #LINE_GRAPH} colors to the given renderer.
 *///from   ww w  .ja v a  2s .  com
public static void apply(LineAndShapeRenderer renderer) {
    int n = 0;
    for (Color c : LINE_GRAPH)
        renderer.setSeriesPaint(n++, c);
}

From source file:org.cyberoam.iview.charts.CustomDomainAxis.java

public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;/*from  w w w  . j a  v  a 2s.  c o m*/
    //   DefaultCategoryDataset dataset=null;
    CustomCategoryDataset datasetCustom = null;

    try {
        ReportColumnBean reportColumnBeanX = null;
        ReportColumnBean reportColumnBeanY = null;
        ReportColumnBean reportColumnBeanZ = null;
        GraphBean graphBean = null;

        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());
        reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        String xColumnDBname = reportColumnBeanX.getDbColumnName();
        reportColumnBeanY = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnDBname = reportColumnBeanY.getDbColumnName();
        String zColumnDBname = null;

        datasetCustom = new CustomCategoryDataset();
        rsw.beforeFirst();
        String data = "";
        int count = -1;
        Boolean showLegend = false;
        if (graphBean.getZColumnId() == -1) {

            while (rsw.next()) {
                data = rsw.getString(xColumnDBname);
                datasetCustom.addValue(rsw.getLong(yColumnDBname), "", data);
            }

        } else {
            String zData;
            showLegend = true;
            reportColumnBeanZ = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                    graphBean.getZColumnId());
            zColumnDBname = reportColumnBeanZ.getDbColumnName();
            while (rsw.next()) {
                data = rsw.getString(xColumnDBname);
                zData = rsw.getString(zColumnDBname);
                datasetCustom.addValue(rsw.getLong(yColumnDBname), zData, data);
                count++;
            }

        }
        chart = ChartFactory.createLineChart("", // chart title
                "", // domain axis label
                "", // range axis label
                datasetCustom, // data
                PlotOrientation.VERTICAL, // orientation
                showLegend, // include legend
                true, // tooltips
                false // urls
        );
        LegendTitle legendTitle = chart.getLegend();
        if (legendTitle != null)
            legendTitle.setItemFont(new Font("Vandara", Font.BOLD, 11));
        chart.setBackgroundPaint(Color.white);
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelInsets(new RectangleInsets(0, 0, 0, 5));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(false);
        rangeAxis.setAxisLineVisible(false);
        CustomDomainAxis catAxis = new CustomDomainAxis();
        CustomDomainAxis.counter = 0;
        CustomDomainAxis.colCount = datasetCustom.getColumnCount();
        catAxis.setTickLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        catAxis.setTickMarksVisible(false);
        catAxis.setTickLabelInsets(new RectangleInsets(10, 15, 30, 10));
        catAxis.setAxisLineVisible(false);
        catAxis.setCategoryLabelPositions(
                CategoryLabelPositions.createUpRotationLabelPositions(20 * Math.PI / 180));
        plot.setDomainAxis(catAxis);
        final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
        renderer.setSeriesPaint(0, Color.DARK_GRAY);
        if (count > 0) {
            Color[] colors = null;
            colors = new Color[5];
            colors[0] = new Color(24, 112, 176);
            colors[1] = new Color(168, 192, 232);
            colors[2] = new Color(248, 120, 8);
            colors[3] = new Color(248, 184, 120);
            colors[4] = new Color(152, 216, 136);
            for (int i = 0; i < count && i < colors.length; i++)
                renderer.setSeriesPaint(i, colors[i]);
        }
    } catch (Exception e) {
        CyberoamLogger.appLog.debug("LineChart: " + e.getMessage(), e);
    }
    return chart;
}

From source file:org.pau.assetmanager.viewmodel.chart.PrepareChart.java

public static void prepareBalanceChart(JFreeChart jfchart) {

    CategoryPlot categoryPlot = ((CategoryPlot) jfchart.getPlot());
    NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
    numberAxis.setAutoRange(true);/*  w  w w.j  ava2  s . co m*/
    numberAxis.setAutoRangeIncludesZero(false);
    categoryPlot.setBackgroundPaint(Color.WHITE);
    categoryPlot.setDomainGridlinePaint(Color.WHITE);
    categoryPlot.setRangeMinorGridlinePaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(Color.BLACK);
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) categoryPlot.getRenderer();

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);

    commonPrepareJFreeChart(renderer);

    renderer.setSeriesPaint(0, Color.black);

    renderer.setSeriesItemLabelPaint(0, Color.black);

}

From source file:org.pau.assetmanager.viewmodel.chart.PrepareChart.java

public static void prepareSimpleJFreeChart(JFreeChart jfchart) {

    CategoryPlot categoryPlot = ((CategoryPlot) jfchart.getPlot());
    categoryPlot.getRangeAxis().resizeRange(1.2);
    categoryPlot.setBackgroundPaint(Color.WHITE);
    categoryPlot.setDomainGridlinePaint(Color.WHITE);
    categoryPlot.setRangeMinorGridlinePaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(Color.BLACK);
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) categoryPlot.getRenderer();

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);

    commonPrepareJFreeChart(renderer);//from ww w .j  a va 2  s.  com

    renderer.setSeriesPaint(0, new Color(0xB3, 0xBE, 0xFF));
    renderer.setSeriesPaint(1, new Color(0xFF, 0xB3, 0xB3));
    renderer.setSeriesPaint(2, new Color(0x61, 0x9E, 0x42));
    renderer.setSeriesPaint(3, Color.black);

    renderer.setSeriesItemLabelPaint(0, new Color(0x21, 0x21, 0xFF));
    renderer.setSeriesItemLabelPaint(1, new Color(0xFF, 0x36, 0x36));
    renderer.setSeriesItemLabelPaint(2, new Color(0x61, 0x9E, 0x42));
    renderer.setSeriesItemLabelPaint(3, Color.black);

}

From source file:spec.reporter.Utils.java

public static void createBmResultGraph(BenchmarkRecord record) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String iterName = "";
    double max = 0;
    double min = Long.MAX_VALUE;
    for (int i = 0; i < record.iterRecords.size(); i++) {
        BenchmarkRecord.IterationRecord iterRecord = (BenchmarkRecord.IterationRecord) record.iterRecords
                .get(i);/*from w w  w  . j av  a  2  s .  c o m*/
        String shortName = iterRecord.iterName.replaceFirst("ation", "");
        if (iterRecord.score > max) {
            max = iterRecord.score;
            iterName = shortName;
        }

        if (iterRecord.score < min) {
            min = iterRecord.score;
        }

        dataset.addValue(iterRecord.score, " ", shortName);
    }

    JFreeChart chart = ChartFactory.createLineChart("  ", "iterations", Constants.WORKLOAD_METRIC, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(new Color(201, 222, 254));
    plot.setRangeGridlinePaint(Color.WHITE);
    if (record.isValidRun() && min != Long.MAX_VALUE) {
        plot.getRangeAxis().setRange(min - 10, max + 10);
    } else {
        plot.getRangeAxis().setRange(0, max + 10);
    }
    ValueMarker vm = new ValueMarker(record.maxScore);
    vm.setLabel(Utils.df.format(record.maxScore));
    vm.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    vm.setLabelTextAnchor(TextAnchor.HALF_ASCENT_LEFT);

    plot.addRangeMarker(vm);
    CategoryMarker marker = new CategoryMarker(iterName);
    marker.setDrawAsLine(true);
    marker.setPaint(vm.getPaint());
    plot.addDomainMarker(marker);
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setFillPaint(Color.WHITE);
    renderer.setSeriesPaint(0, Color.BLUE.darker());

    try {
        ChartUtilities.saveChartAsJPEG(new File(Utils.getFullImageName(record.name + "_results")), chart, 300,
                200);
    } catch (Exception e) {
        System.out.println("Problems...");
    }
}

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java

private static JFreeChart createLineChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createLineChart("Line Chart Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from   ww w.ja  v  a 2s . c  om*/

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setUseOutlinePaint(true);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    return chart;

}

From source file:playground.artemc.calibration.charts.AddSecondChart.java

public void addChart() {

    plot.setDataset(1, dataset);/*from w w w .jav a  2s . com*/
    plot.mapDatasetToRangeAxis(1, 0);

    final LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    plot.setRenderer(1, renderer);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setDomainGridlinesVisible(true);

}

From source file:playground.artemc.calibration.charts.AddSecondChart.java

public void addChartAndAxis() {

    //this.plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));       
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    //final CategoryAxis domainAxis = plot.getDomainAxis();
    //domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);

    final ValueAxis axis2 = new NumberAxis(yAxisLabel);
    axis2.setRange(lowerLimit, upperLimit);
    plot.setRangeAxis(1, axis2);/*from  w w  w.j a  v  a2s.  c  om*/
    plot.setDataset(1, dataset);
    plot.mapDatasetToRangeAxis(1, 1);

    final LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    plot.setRenderer(1, renderer);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setDomainGridlinesVisible(true);

}

From source file:com.thalesgroup.hudson.plugins.cppcheck.graph.CppcheckGraph.java

/**
 * Apply color palette to the lines in the graph.
 * /*from  ww  w. j a v a2 s. com*/
 * @param renderer the graph renderer
 * @see ColorPalette#apply(LineAndShapeRenderer)
 */
private void applyColorPalette(LineAndShapeRenderer renderer) {
    int n = 0;

    for (Color c : colors) {
        renderer.setSeriesPaint(n++, c);
    }
}

From source file:hudson.model.LoadStatistics.java

protected void configureRenderer(LineAndShapeRenderer renderer) {
    renderer.setSeriesPaint(0, ColorPalette.BLUE); // total
    renderer.setSeriesPaint(1, ColorPalette.RED); // busy
    renderer.setSeriesPaint(2, ColorPalette.GREY); // queue
}