Search in sources :

Example 6 with StackedAreaRenderer

use of org.jfree.chart.renderer.category.StackedAreaRenderer in project java-examples by urvanov-ru.

the class MainClass method main.

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setSize(new Dimension(600, 400));
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(1.6, "roKey1", "columnKey1");
    dataset.addValue(0.3, "roKey1", "columnKey2");
    dataset.addValue(2.3, "roKey1", "columnKey3");
    JFreeChart chart = ChartFactory.createStackedAreaChart(// chart title
    "Serial Data", // domain axis label
    "Domain", // range axis label
    "Range", // initial series
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips?
    true, // URLs?
    false);
    // set chart background
    chart.setBackgroundPaint(Color.white);
    // set a few custom plot features
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    // set the plot's axes to display integers
    // TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    // CategoryAxis domain = (CategoryAxis) plot.getDomainAxis();
    // NumberAxis range = (NumberAxis) plot.getRangeAxis();
    // range.setStandardTickUnits(ticks);
    // render shapes and lines
    StackedAreaRenderer renderer = new StackedAreaRenderer();
    plot.setRenderer(renderer);
    // set the renderer's stroke
    // Stroke stroke = new BasicStroke(
    // 3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    // renderer.setBaseOutlineStroke(stroke);
    // label the points
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    StandardCategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator(StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);
    ChartPanel chartPanel = new ChartPanel(chart, false);
    chartPanel.setPreferredSize(new Dimension(640, 480));
    frame.add(chartPanel);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Also used : StandardCategoryItemLabelGenerator(org.jfree.chart.labels.StandardCategoryItemLabelGenerator) ChartPanel(org.jfree.chart.ChartPanel) JFrame(javax.swing.JFrame) Color(java.awt.Color) Dimension(java.awt.Dimension) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer) NumberFormat(java.text.NumberFormat)

Example 7 with StackedAreaRenderer

use of org.jfree.chart.renderer.category.StackedAreaRenderer in project hudson-2.x by hudson.

the class AbstractTestResultAction method createChart.

private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) {
    final String relPath = getRelPath(req);
    final JFreeChart chart = ChartFactory.createStackedAreaChart(// chart title
    null, // unused
    null, // range axis label
    "count", // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    false, // tooltips
    true, // urls
    false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    // set the background color for the chart...
    // final StandardLegend legend = (StandardLegend) chart.getLegend();
    // legend.setAnchor(StandardLegend.SOUTH);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    // plot.setDomainGridlinesVisible(true);
    // plot.setDomainGridlinePaint(Color.white);
    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);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    StackedAreaRenderer ar = new StackedAreaRenderer2() {

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            return relPath + label.build.getNumber() + "/testReport/";
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            AbstractTestResultAction a = label.build.getAction(AbstractTestResultAction.class);
            switch(row) {
                case 0:
                    return String.valueOf(Messages.AbstractTestResultAction_fail(label.build.getDisplayName(), a.getFailCount()));
                case 1:
                    return String.valueOf(Messages.AbstractTestResultAction_skip(label.build.getDisplayName(), a.getSkipCount()));
                default:
                    return String.valueOf(Messages.AbstractTestResultAction_test(label.build.getDisplayName(), a.getTotalCount()));
            }
        }
    };
    plot.setRenderer(ar);
    // Failures.
    ar.setSeriesPaint(0, ColorPalette.RED);
    // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW);
    // Total.
    ar.setSeriesPaint(2, ColorPalette.BLUE);
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) NumberOnlyBuildLabel(hudson.util.ChartUtil.NumberOnlyBuildLabel) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer)

Example 8 with StackedAreaRenderer

use of org.jfree.chart.renderer.category.StackedAreaRenderer in project pentaho-platform by pentaho.

the class JFreeChartEngine method createAreaChart.

private static JFreeChart createAreaChart(final CategoryDatasetChartDefinition chartDefinition) {
    // TODO Make the following accessible from the chartDefinition
    String categoryAxisLabel = null;
    String valueAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------
    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();
    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
    AreaRenderer renderer = chartDefinition.isStacked() ? new StackedAreaRenderer() : new AreaRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }
    CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) XYAreaRenderer(org.jfree.chart.renderer.xy.XYAreaRenderer) XYStepAreaRenderer(org.jfree.chart.renderer.xy.XYStepAreaRenderer) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer) AreaRenderer(org.jfree.chart.renderer.category.AreaRenderer) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) ValueAxis(org.jfree.chart.axis.ValueAxis) StandardCategoryURLGenerator(org.jfree.chart.urls.StandardCategoryURLGenerator) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer)

Aggregations

StackedAreaRenderer (org.jfree.chart.renderer.category.StackedAreaRenderer)8 JFreeChart (org.jfree.chart.JFreeChart)6 NumberAxis (org.jfree.chart.axis.NumberAxis)6 CategoryPlot (org.jfree.chart.plot.CategoryPlot)6 CategoryAxis (org.jfree.chart.axis.CategoryAxis)5 CategoryDataset (org.jfree.data.category.CategoryDataset)4 RectangleInsets (org.jfree.ui.RectangleInsets)3 ShiftedCategoryAxis (hudson.util.ShiftedCategoryAxis)2 StackedAreaRenderer2 (hudson.util.StackedAreaRenderer2)2 ValueAxis (org.jfree.chart.axis.ValueAxis)2 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)2 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)2 NumberOnlyBuildLabel (hudson.util.ChartUtil.NumberOnlyBuildLabel)1 DataSetBuilder (hudson.util.DataSetBuilder)1 Graph (hudson.util.Graph)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 JFrame (javax.swing.JFrame)1