Example usage for org.jfree.chart.renderer.category DefaultCategoryItemRenderer DefaultCategoryItemRenderer

List of usage examples for org.jfree.chart.renderer.category DefaultCategoryItemRenderer DefaultCategoryItemRenderer

Introduction

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

Prototype

DefaultCategoryItemRenderer

Source Link

Usage

From source file:com.thalesgroup.hudson.plugins.sourcemonitor.SourceMonitorChartBuilder.java

public static JFreeChart buildChart(SourceMonitorBuildAction action) {
    JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, "Number of errors", buildDataset(action),
            PlotOrientation.VERTICAL, true, false, true);

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);//from www .j  av a 2s  . c  o  m
    plot.setForegroundAlpha(0.8f);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    CategoryItemRenderer firstRender = new DefaultCategoryItemRenderer();
    SourceMonitorRenderer renderer = new SourceMonitorRenderer(action.getUrlName());
    plot.setRenderer(firstRender);

    return chart;
}

From source file:com.thalesgroup.hudson.plugins.cccc.CcccChartBuilder.java

protected JFreeChart createGraph() {

    JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, "Number of modules",
            buildDataset(action), PlotOrientation.VERTICAL, true, false, true);

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);//from w ww.j  ava 2 s . c o m
    plot.setForegroundAlpha(0.8f);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    CategoryItemRenderer firstRender = new DefaultCategoryItemRenderer();
    CcccAreaRenderer renderer = new CcccAreaRenderer(action.getUrlName());
    plot.setRenderer(firstRender);

    //Second
    NumberAxis axis2 = new NumberAxis("Lines of Code");
    axis2.setLabelPaint(Color.BLUE);
    axis2.setAxisLinePaint(Color.BLUE);
    axis2.setTickLabelPaint(Color.BLUE);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    categoryPlot.setRangeAxis(1, axis2);
    //CategoryAxis categoryAxis = categoryPlot.getDomainAxis();
    categoryPlot.setDataset(1, buildDataset2(action));
    categoryPlot.mapDatasetToRangeAxis(1, 1);
    CategoryItemRenderer rendu = new DefaultCategoryItemRenderer();
    rendu.setBasePaint(Color.BLUE);
    categoryPlot.setRenderer(1, rendu);

    //Third
    NumberAxis axis3 = new NumberAxis("McCabe's Cyclomatic Number");
    axis3.setLabelPaint(Color.GREEN);
    axis3.setAxisLinePaint(Color.GREEN);
    axis3.setTickLabelPaint(Color.GREEN);
    CategoryPlot categoryPlot3 = chart.getCategoryPlot();
    categoryPlot3.setRangeAxis(2, axis3);
    categoryPlot3.setDataset(2, buildDataset3(action));
    categoryPlot3.mapDatasetToRangeAxis(2, 2);
    categoryPlot3.mapDatasetToDomainAxis(2, 0);
    CategoryItemRenderer rendu3 = new DefaultCategoryItemRenderer();
    rendu3.setBasePaint(Color.GREEN);
    categoryPlot3.setRenderer(2, rendu3);

    return chart;
}

From source file:charts.Chart.java

public static Vector MultipleStepChartOverlayed(CategoryDataset[] datasets1, CategoryDataset[] datasets2,
        String title, String x_axis_label, String y_axis_label, boolean showlegend, float maxvalue,
        float minvalue, boolean showchart) {

    CategoryAxis domainAxis = new CategoryAxis(x_axis_label);
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    //if (minvalue == 0 && maxvalue == 0) {
    //    rangeAxis.setAutoRange(true);
    //} else {/*from   w  w w . j a va 2s  . c om*/
    //    rangeAxis.setRange(minvalue, maxvalue);
    //}
    rangeAxis.setAutoRange(true);

    CombinedDomainCategoryPlot parent = new CombinedDomainCategoryPlot(new CategoryAxis(x_axis_label));

    for (int i = 0; i < datasets1.length; i++) {
        CategoryItemRenderer renderer1 = new CategoryStepRenderer(true);
        renderer1.setBaseStroke(new BasicStroke(2.0f));
        renderer1.setBaseSeriesVisibleInLegend(showlegend);

        CategoryPlot subplot = new CategoryPlot(datasets1[i], domainAxis, rangeAxis, renderer1);
        subplot.setBackgroundPaint(Color.white);
        subplot.setRangeGridlinePaint(Color.black);
        subplot.setDomainGridlinesVisible(true);

        DefaultCategoryItemRenderer renderer2 = new DefaultCategoryItemRenderer();
        renderer2.setSeriesPaint(0, Color.LIGHT_GRAY);
        renderer2.setBaseStroke(new BasicStroke(2.0f));
        renderer2.setShapesVisible(true);
        renderer2.setBaseSeriesVisibleInLegend(false);

        subplot.setDataset(1, datasets2[i]);
        subplot.setRenderer(1, renderer2);
        //subplot.setDrawSharedDomainAxis(true);
        parent.add(subplot, 1);
    }

    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));

    //if (showchart) {
    JFrame chartwindow = new JFrame(title);
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(true);
    //}
    Vector res = new Vector();
    res.add(0, jfreechart);
    res.add(1, chartwindow);
    return res;
}

From source file:charts.Chart.java

public static Vector MultipleStepChartOverlayedMA(CategoryDataset[] datasets, String title, String x_axis_label,
        String y_axis_label, boolean showlegend, float maxvalue, float minvalue, boolean showchart) {

    CategoryAxis domainAxis = new CategoryAxis(x_axis_label);
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    rangeAxis.setAutoRange(true);/*from   w w  w  . j a  v  a  2 s  . co  m*/
    CombinedDomainCategoryPlot parent = new CombinedDomainCategoryPlot(new CategoryAxis(x_axis_label));
    DefaultCategoryItemRenderer renderer0 = new DefaultCategoryItemRenderer();
    renderer0.setBaseStroke(new BasicStroke(2.0f));
    renderer0.setBaseSeriesVisibleInLegend(showlegend);
    renderer0.setSeriesPaint(0, Color.RED);//sinal original
    renderer0.setShapesVisible(false);
    CategoryPlot subplot = new CategoryPlot(datasets[0], domainAxis, rangeAxis, renderer0);
    subplot.setBackgroundPaint(Color.white);
    subplot.setRangeGridlinePaint(Color.black);
    subplot.setDomainGridlinesVisible(true);
    parent.add(subplot);

    CategoryAxis domainAxis1 = new CategoryAxis(x_axis_label);
    ValueAxis rangeAxis1 = new NumberAxis(y_axis_label);
    rangeAxis1.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    rangeAxis1.setAutoRange(true);

    CategoryItemRenderer renderer1 = new CategoryStepRenderer(true);
    renderer1.setBaseStroke(new BasicStroke(2.0f));
    renderer1.setBaseSeriesVisibleInLegend(showlegend);
    renderer1.setSeriesPaint(0, Color.BLUE);//sinal quantizado
    CategoryPlot subplot1 = new CategoryPlot(datasets[1], domainAxis1, rangeAxis1, renderer1);
    //subplot.setDataset(1, datasets[1]);
    //subplot.setRenderer(1, renderer1);
    parent.add(subplot1);

    DefaultCategoryItemRenderer renderer2 = new DefaultCategoryItemRenderer();
    renderer2.setBaseStroke(new BasicStroke(2.0f));
    renderer2.setBaseSeriesVisibleInLegend(showlegend);
    renderer2.setShapesVisible(false);
    renderer2.setSeriesPaint(0, Color.BLACK);//sinal normalizado
    subplot1.setDataset(1, datasets[2]);
    subplot1.setRenderer(1, renderer2);

    for (int i = 3; i < datasets.length; i++) {
        DefaultCategoryItemRenderer renderer3 = new DefaultCategoryItemRenderer();
        renderer3.setBaseStroke(new BasicStroke(2.0f));
        renderer3.setBaseSeriesVisibleInLegend(showlegend);
        renderer3.setShapesVisible(false);
        renderer3.setSeriesPaint(0, Color.LIGHT_GRAY);//limiares utilizados para quantizacao.
        subplot1.setDataset(i - 1, datasets[i]);
        subplot1.setRenderer(i - 1, renderer3);
    }

    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    JPanel retorno = new ChartPanel(jfreechart);
    retorno.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    JFrame chartwindow = new JFrame(title);
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(showchart);
    Vector res = new Vector();
    res.add(0, jfreechart);
    res.add(1, chartwindow);
    res.add(2, retorno);
    return res;
}

From source file:charts.Chart.java

public static Vector MultipleLineChart(CategoryDataset[] datasets, String title, String x_axis_label,
        String y_axis_label, boolean showlegend, float maxvalue, float minvalue, boolean showchart) {

    CategoryAxis domainAxis = new CategoryAxis(x_axis_label);
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    if (minvalue == 0 && maxvalue == 0) {
        rangeAxis.setAutoRange(true);/*from w  w  w . ja  v  a  2  s.c o m*/
    } else {
        rangeAxis.setRange(minvalue, maxvalue);
    }
    CombinedDomainCategoryPlot parent = new CombinedDomainCategoryPlot(new CategoryAxis(x_axis_label));

    for (int i = 0; i < datasets.length; i++) {
        CategoryItemRenderer renderer = new DefaultCategoryItemRenderer();//new CategoryStepRenderer(true);
        renderer.setBaseStroke(new BasicStroke(2.0f));
        renderer.setBaseSeriesVisibleInLegend(showlegend);
        CategoryPlot subplot = new CategoryPlot(datasets[i], domainAxis, rangeAxis, renderer);
        subplot.setBackgroundPaint(Color.white);
        subplot.setRangeGridlinePaint(Color.black);
        subplot.setDomainGridlinesVisible(true);
        //subplot.setDrawSharedDomainAxis(true);
        parent.add(subplot, 1);
    }

    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));

    //if (showchart) {
    JFrame chartwindow = new JFrame(title);
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(true);
    //}
    Vector res = new Vector();
    res.add(0, jfreechart);
    res.add(1, chartwindow);
    return res;
}