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

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

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category CategoryItemRenderer 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:cl.apr.pdf.chart.BarChartAviso.java

public static BufferedImage crearBarchart(List<BarChartItem> barChartItems) {
    BufferedImage bi = null;// ww w  .j  ava2 s.  co m
    try {

        ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme());
        //ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme());

        /* Step - 1: Define the data for the bar chart  */
        DefaultCategoryDataset my_bar_chart_dataset = new DefaultCategoryDataset();
        int i = 0;
        for (BarChartItem barChartItem : barChartItems) {
            if (barChartItem.getNombre().equals("-")) {
                my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", (++i) + "");
            } else
                my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", barChartItem.getNombre());
        }
        //                my_bar_chart_dataset.addValue(34, "mes", "Ene");
        //                my_bar_chart_dataset.addValue(25, "mes", "Feb");
        //                my_bar_chart_dataset.addValue(22, "mes", "Mar");
        //                my_bar_chart_dataset.addValue(12, "mes", "Abr");
        //                my_bar_chart_dataset.addValue(40, "mes", "May");
        //                my_bar_chart_dataset.addValue(30, "mes", "jun");
        //                my_bar_chart_dataset.addValue(2, "mes", "Jul");
        //                my_bar_chart_dataset.addValue(15, "mes", "Ago");

        /* Step -2:Define the JFreeChart object to create bar chart */
        //JFreeChart chart=ChartFactory.createBarChart("Detalle de sus consumos","","MT3",my_bar_chart_dataset,PlotOrientation.VERTICAL,true,true,false);    
        JFreeChart chart = ChartFactory.createBarChart("", "", "MT3", my_bar_chart_dataset,
                PlotOrientation.VERTICAL, true, true, false);

        //chart.setBackgroundPaint(Color.lightGray);
        // get a reference to the plot for further customisation... 
        final CategoryPlot plot = chart.getCategoryPlot();
        CategoryItemRenderer renderer = new CustomRenderer();

        renderer.setSeriesPaint(0, Color.DARK_GRAY);

        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        chart.setBorderVisible(false);
        chart.setBackgroundPaint(Color.white);
        chart.setBorderStroke(null);
        chart.getLegend().visible = false;
        /* Step -3: Write the output as PNG file with bar chart information */
        int width = 480; /* Width of the image */
        int height = 250; /* Height of the image */
        bi = chart.createBufferedImage(width, height);

        /*
                
        File BarChart=new File("output_chart.png");              
        ChartUtilities.saveChartAsPNG(BarChart,BarChartObject,width,height); 
                */
    } catch (Exception i) {
        System.out.println(i);
    }

    return bi;
}

From source file:org.nbheaven.sqe.codedefects.dashboard.controlcenter.panels.Statistics.java

private static JFreeChart createOverviewPanel(DefaultCategoryDataset dataSet) {

    JFreeChart overview = org.jfree.chart.ChartFactory.createStackedBarChart(null, null, "CodeDefects", dataSet,
            PlotOrientation.HORIZONTAL, false, true, false);
    overview.setBorderVisible(false);/* w w w.  j  a va 2  s. co m*/
    overview.setBackgroundPaint(Color.WHITE);
    overview.setAntiAlias(true);
    overview.setNotify(true);

    CategoryPlot overviewPlot = overview.getCategoryPlot();
    overviewPlot.setRangeGridlinePaint(Color.BLACK);
    overviewPlot.setDomainGridlinePaint(Color.BLACK);
    overviewPlot.setBackgroundPaint(Color.WHITE);
    overviewPlot.setForegroundAlpha(0.7f);
    overviewPlot.setRangeAxisLocation(AxisLocation.getOpposite(overviewPlot.getRangeAxisLocation()));

    CategoryAxis domainAxis = overviewPlot.getDomainAxis();
    domainAxis.setVisible(true);

    LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects");
    rangeAxis.setLabel(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    overviewPlot.setRangeAxis(rangeAxis);

    CategoryItemRenderer categoryItemRenderer = new StackedBarRenderer(); //3D();
    //        categoryItemRenderers[0].setPaint(Color.RED);
    categoryItemRenderer.setSeriesPaint(0, Color.RED);
    categoryItemRenderer.setSeriesPaint(1, Color.ORANGE);
    categoryItemRenderer.setSeriesPaint(2, Color.YELLOW);

    categoryItemRenderer.setBaseItemLabelsVisible(true);

    overviewPlot.setRenderer(categoryItemRenderer);

    return overview;
}

From source file:net.sf.maltcms.common.charts.api.ChartCustomizer.java

/**
 *
 * @param plot// w w  w . j av a2 s.  c o  m
 * @param alpha
 * @param colors
 */
public static void setSeriesColors(CategoryPlot plot, float alpha, List<Color> colors) {
    int datasets = plot.getDatasetCount();
    for (int i = 0; i < datasets; i++) {
        CategoryDataset ds = plot.getDataset(i);
        CategoryItemRenderer renderer = plot.getRenderer(i);
        //            System.out.println("Dataset has " + ds.getRowCount() + " rows");
        for (int j = 0; j < ds.getRowCount(); j++) {
            renderer.setSeriesPaint(j, withAlpha(colors.get(j), alpha));
        }
    }
}

From source file:net.sf.maltcms.common.charts.api.ChartCustomizer.java

/**
 *
 * @param plot/*from  w w w .  j  a  va 2  s .  com*/
 * @param alpha
 */
public static void setSeriesColors(CategoryPlot plot, float alpha) {

    int datasets = plot.getDatasetCount();
    for (int i = 0; i < datasets; i++) {
        CategoryDataset ds = plot.getDataset(i);
        CategoryItemRenderer renderer = plot.getRenderer(i);
        //            System.out.println("Dataset has " + ds.getRowCount() + " rows");
        for (int j = 0; j < ds.getRowCount(); j++) {
            renderer.setSeriesPaint(j, withAlpha(plotColors[j % plotColors.length], alpha));
        }
    }
}

From source file:presentation.webgui.vitroappservlet.StyleCreator.java

private static JFreeChart createChart(CategoryDataset dataset, Vector<String> givCategColors,
        Model3dStylesEntry givStyleEntry) {
    String capSimpleName = givStyleEntry.getCorrCapability();
    capSimpleName = capSimpleName.replaceAll(Capability.dcaPrefix, "");
    JFreeChart chart = ChartFactory.createBarChart("Style Legend for " + capSimpleName, // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            true, false);/*from  w ww  . ja va 2  s  . c  o m*/

    chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 14));
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white); // seen
    CategoryPlot plot = chart.getCategoryPlot();
    chart.setPadding(new RectangleInsets(0, 0, 0, 0)); //new

    plot.setNoDataMessage("NO DATA!");

    Paint[] tmpPaintCategories = { Color.white };
    if (givCategColors.size() > 0) {
        tmpPaintCategories = new Paint[givCategColors.size()];
        for (int i = 0; i < givCategColors.size(); i++) {
            tmpPaintCategories[i] = Color.decode(givCategColors.elementAt(i));
        }
    }

    CategoryItemRenderer renderer = new CustomRenderer(tmpPaintCategories);

    renderer.setSeriesPaint(0, new Color(255, 204, 51)); //new

    plot.setRenderer(renderer);

    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); //new
    plot.setForegroundAlpha(1f); //new
    plot.setBackgroundAlpha(1f); //new
    plot.setInsets(new RectangleInsets(5, 0, 5, 0)); //new was 5,0,5,0
    plot.setRangeGridlinesVisible(false); //new was true
    plot.setBackgroundPaint(Color.white);//new: was (Color.lightGray);
    plot.setOutlinePaint(Color.white);

    //plot.setOrientation(PlotOrientation.HORIZONTAL);

    CategoryAxis domainAxis = plot.getDomainAxis();

    domainAxis.setLowerMargin(0.04);
    domainAxis.setUpperMargin(0.04);
    domainAxis.setVisible(true);
    domainAxis.setLabelAngle(Math.PI / 2);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(0.0, 100.0); // new: was 100
    rangeAxis.setVisible(false);
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:org.fhaes.fhrecorder.view.GraphSummaryOverlay.java

/**
 * This method creates the JFreeChart based on all of the incoming data sets.
 * /*from  w  w w  .  j av  a2s  .  c  o  m*/
 * @param eventsDataset This is the data set corresponding to the events bar chart graph.
 * @param recordersDataset This is the data set corresponding to the recorders line graph.
 * @param samplesDataset This is the data set corresponding to the samples line graph.
 * @return This returns a JFreeChart with all 3 of the graphs described.
 */
private static JFreeChart createChart(final CategoryDataset eventsDataset,
        final CategoryDataset recordersDataset, final CategoryDataset samplesDataset) {

    final CategoryItemRenderer eventsRenderer = new BarRenderer();
    ((BarRenderer) eventsRenderer).setBarPainter(new StandardBarPainter()); // Remove shine
    ((BarRenderer) eventsRenderer).setShadowVisible(false);
    eventsRenderer.setSeriesPaint(0, new Color(224, 0, 51));
    eventsRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

    final CategoryPlot plot = new CategoryPlot();
    plot.setDataset(eventsDataset);
    plot.setRenderer(eventsRenderer);

    plot.setDomainAxis(new CategoryAxis(""));
    plot.setRangeAxis(new NumberAxis(""));

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    plot.setDomainAxis(new NumericCategoryAxis());

    plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));

    final CategoryItemRenderer recorderRenderer = new LineAndShapeRenderer(true, false);
    recorderRenderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 10.0f, 6.0f }, 0.0f));
    recorderRenderer.setSeriesPaint(0, new Color(102, 102, 255));
    recorderRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

    // Temporarily removing recorders dataset
    // plot.setDataset(1, recordersDataset);
    // plot.setRenderer(1, recorderRenderer);

    final CategoryItemRenderer samplesRenderer = new LineAndShapeRenderer(true, false);
    samplesRenderer.setSeriesStroke(0, new BasicStroke(2.0f));
    samplesRenderer.setSeriesPaint(0, new Color(0, 153, 0));
    samplesRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    plot.setDataset(2, samplesDataset);
    plot.setRenderer(2, samplesRenderer);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    plot.getDomainAxis().setLowerMargin(0.025);
    plot.getDomainAxis().setUpperMargin(0.025);

    final JFreeChart chart = new JFreeChart(plot);

    return chart;
}

From source file:spec.reporter.Utils.java

public static void generateMainChart(double compositeScore, TreeMap<String, Double> scores) {

    // Valid benchmarks + room for all possible extra - compiler, crypto, scimark, scimark.small, scimark.large, startup, xml, composite score
    Color[] colors = new Color[scores.size() + 8];

    // create the dataset...
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int count = 0;

    Iterator<String> iteratorBenchmarks = scores.keySet().iterator();
    while (iteratorBenchmarks.hasNext()) {
        String key = iteratorBenchmarks.next();
        Double score = scores.get(key);
        if (Utils.isValidScore(score)) {
            dataset.addValue(score, key, key);
            colors[count++] = (Color) colorMap.get(key);
        }//from  w ww. j  a  va 2 s.com
    }

    if (Utils.isValidScore(compositeScore)) {
        dataset.addValue(compositeScore, Utils.CSCORE_NAME, Utils.CSCORE_NAME);
        colors[count++] = (Color) colorMap.get(Utils.CSCORE_NAME);
    }

    JFreeChart chart = ChartFactory.createStackedBarChart("Scores", // chart title
            "", // domain axis label
            "", dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            false, // tooltips?
            false // URLs?
    );

    CategoryItemRenderer renderer = chart.getCategoryPlot().getRendererForDataset(dataset);
    for (int i = 0; i < count; i++) {
        Color paint = (Color) colors[i];
        if (paint != null) {
            renderer.setSeriesPaint(i, paint);
        }
    }

    try {
        ChartUtilities.saveChartAsJPEG(new File(getFullImageName("all")), chart, 600,
                50 + (dataset.getRowCount()) * 20);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.sf.maltcms.chromaui.charts.ChartCustomizer.java

/**
 *
 * @param plot// w  w  w. j a  v a 2s. co m
 * @param alpha
 */
public static void setSeriesColors(CategoryPlot plot, float alpha) {

    int datasets = plot.getDatasetCount();
    for (int i = 0; i < datasets; i++) {
        CategoryDataset ds = plot.getDataset(i);
        CategoryItemRenderer renderer = plot.getRenderer(i);
        Logger.getLogger(ChartCustomizer.class.getName()).log(Level.INFO, "Dataset has {0} rows",
                ds.getRowCount());
        Logger.getLogger(ChartCustomizer.class.getName()).log(Level.INFO, "Dataset has {0} columns",
                ds.getColumnCount());
        for (int j = 0; j < ds.getRowCount(); j++) {
            renderer.setSeriesPaint(j, withAlpha(plotColors[j % plotColors.length], alpha));
        }
    }
}

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * DOC xqliu Comment method "decorateColumnDependency".
 * /*  w  ww . j  a v  a  2  s .  co m*/
 * @param chart
 */
public static void decorateColumnDependency(JFreeChart chart) {
    decorate(chart, PlotOrientation.HORIZONTAL);
    CategoryItemRenderer renderer = ((CategoryPlot) chart.getPlot()).getRenderer();
    renderer.setSeriesPaint(0, COLOR_LIST.get(1));
    renderer.setSeriesPaint(1, COLOR_LIST.get(2));
}

From source file:net.sf.maltcms.chromaui.charts.ChartCustomizer.java

/**
 *
 * @param plot//w  w  w .  j a  v  a  2s  .c o  m
 * @param alpha
 * @param colors
 */
public static void setSeriesColors(CategoryPlot plot, float alpha, List<Color> colors) {
    int datasets = plot.getDatasetCount();
    for (int i = 0; i < datasets; i++) {
        CategoryDataset ds = plot.getDataset(i);
        CategoryItemRenderer renderer = plot.getRenderer(i);
        Logger.getLogger(ChartCustomizer.class.getName()).log(Level.INFO, "Dataset has {0} rows",
                ds.getRowCount());
        Logger.getLogger(ChartCustomizer.class.getName()).log(Level.INFO, "Dataset has {0} columns",
                ds.getColumnCount());
        for (int j = 0; j < ds.getRowCount(); j++) {
            //                if (ds.getRowCount() != colors.size()) {
            //                    throw new IllegalArgumentException("Number of datasets and number of colors must be equal!");
            //                }
            renderer.setSeriesPaint(j, withAlpha(colors.get(j), alpha));
        }
    }
}