Search in sources :

Example 1 with RectangleInsets

use of org.jfree.ui.RectangleInsets in project MSEC by Tencent.

the class Tools method generateFullDayChart.

public static String generateFullDayChart(String filename, OneDayValue[] data, String title) {
    if (data[0].getValues().length != 1440) {
        return "data size invalid";
    }
    if (data.length > 1) {
        if (data[1].getValues() == null || data[1].getValues().length != 1440) {
            return "data 1 invalid";
        }
    }
    XYDataset xydataset = createDataset(data);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true);
    try {
        XYPlot xyplot = (XYPlot) jfreechart.getPlot();
        //线条
        xyplot.setRangeGridlinePaint(ChartColor.GRAY);
        xyplot.setBackgroundPaint(ChartColor.WHITE);
        xyplot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
        //去掉边框
        xyplot.setOutlinePaint(null);
        //横轴
        DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
        dateaxis.setDateFormatOverride(new SimpleDateFormat("H"));
        //水平底部标题
        dateaxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
        dateaxis.setLabelPaint(ChartColor.black);
        dateaxis.setTickLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
        dateaxis.setTickLabelPaint(ChartColor.black);
        GregorianCalendar endgc = (GregorianCalendar) gc.clone();
        endgc.add(GregorianCalendar.DATE, 1);
        dateaxis.setMaximumDate(endgc.getTime());
        dateaxis.setTickMarksVisible(true);
        dateaxis.setTickMarkInsideLength(5);
        dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2));
        //dateaxis.setVerticalTickLabels(true);
        dateaxis.setLabel("");
        //纵轴
        //获取柱状
        ValueAxis rangeAxis = xyplot.getRangeAxis();
        rangeAxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
        rangeAxis.setLabelPaint(ChartColor.black);
        rangeAxis.setTickLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
        rangeAxis.setTickLabelPaint(ChartColor.black);
        rangeAxis.setLowerBound(0);
        rangeAxis.setUpperBound(Tools.upperBound(data[0].getMax()));
        NumberAxis numAxis = (NumberAxis) rangeAxis;
        numAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        //图例
        jfreechart.getLegend().setItemFont(new Font("微软雅黑", Font.PLAIN, 12));
        jfreechart.getLegend().setItemPaint(ChartColor.black);
        //去掉边框
        jfreechart.getLegend().setBorder(0, 0, 0, 0);
        //标题
        //设置标题字体
        jfreechart.getTitle().setFont(new Font("微软雅黑", Font.BOLD, 16));
        jfreechart.getTitle().setPaint(ChartColor.black);
        int w = 500;
        int h = 300;
        ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h);
        return "success";
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) RectangleInsets(org.jfree.ui.RectangleInsets) XYDataset(org.jfree.data.xy.XYDataset) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 2 with RectangleInsets

use of org.jfree.ui.RectangleInsets in project MSEC by Tencent.

the class Tools method generateDaysChart.

public static String generateDaysChart(String filename, ArrayList<OneDayValue> data, OneAttrDaysChart chart, String title, int duration) {
    if (data.size() == 0) {
        return "data size invalid";
    }
    int date = Integer.parseInt(data.get(0).getDate());
    GregorianCalendar startgc = new GregorianCalendar(date / 10000, date % 10000 / 100 - 1, date % 100);
    XYDataset xydataset = createDaysDataset(data, startgc, chart);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true);
    try {
        XYPlot xyplot = (XYPlot) jfreechart.getPlot();
        //线条
        xyplot.setRangeGridlinePaint(ChartColor.GRAY);
        xyplot.setBackgroundPaint(ChartColor.WHITE);
        xyplot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
        //去掉边框
        xyplot.setOutlinePaint(null);
        //横轴
        DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
        dateaxis.setDateFormatOverride(new SimpleDateFormat("MM/dd"));
        //水平底部标题
        dateaxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
        dateaxis.setLabelPaint(ChartColor.black);
        dateaxis.setTickLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
        dateaxis.setTickLabelPaint(ChartColor.black);
        dateaxis.setMinimumDate(startgc.getTime());
        GregorianCalendar endgc = (GregorianCalendar) startgc.clone();
        endgc.add(GregorianCalendar.DATE, duration);
        dateaxis.setMaximumDate(endgc.getTime());
        dateaxis.setTickMarksVisible(true);
        dateaxis.setTickMarkInsideLength(5);
        dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1));
        //dateaxis.setVerticalTickLabels(true);
        dateaxis.setLabel("");
        //纵轴
        //获取柱状
        ValueAxis rangeAxis = xyplot.getRangeAxis();
        rangeAxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
        rangeAxis.setLabelPaint(ChartColor.black);
        rangeAxis.setTickLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
        rangeAxis.setTickLabelPaint(ChartColor.black);
        rangeAxis.setLowerBound(0);
        rangeAxis.setUpperBound(Tools.upperBound(chart.getMax()));
        NumberAxis numAxis = (NumberAxis) rangeAxis;
        numAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        //图例
        jfreechart.getLegend().setItemFont(new Font("微软雅黑", Font.PLAIN, 12));
        jfreechart.getLegend().setItemPaint(ChartColor.black);
        //去掉边框
        jfreechart.getLegend().setBorder(0, 0, 0, 0);
        //标题
        //设置标题字体
        jfreechart.getTitle().setFont(new Font("微软雅黑", Font.BOLD, 16));
        jfreechart.getTitle().setPaint(ChartColor.black);
        int w = 500;
        int h = 300;
        ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h);
        return "success";
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) RectangleInsets(org.jfree.ui.RectangleInsets) XYDataset(org.jfree.data.xy.XYDataset) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 3 with RectangleInsets

use of org.jfree.ui.RectangleInsets in project violations-plugin by jenkinsci.

the class SeverityTypeDataSet method createChart.

/**
     * Create a JFree chart for this dataset.
     *
     * @return the chart.
     */
public JFreeChart createChart() {
    CategoryDataset dataset = buildDataSet();
    JFreeChart chart = // chart
    ChartFactory.createStackedAreaChart(// chart
    null, // unused
    null, // range axis label
    "count", // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(ALPHA);
    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());
    if (Boolean.getBoolean(AbstractViolationsBuildAction.VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
        rangeAxis.setAutoRange(true);
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setAutoRangeMinimumSize(50);
    }
    StackedAreaRenderer renderer = new StackedAreaRenderer2();
    plot.setRenderer(renderer);
    renderer.setSeriesPaint(2, RED);
    renderer.setSeriesPaint(1, VIOLET);
    renderer.setSeriesPaint(0, YELLOW);
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, INSET));
    return chart;
}
Also used : ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) LegendTitle(org.jfree.chart.title.LegendTitle) StackedAreaRenderer2(hudson.util.StackedAreaRenderer2) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer)

Example 4 with RectangleInsets

use of org.jfree.ui.RectangleInsets in project hudson-2.x by hudson.

the class Job method getBuildTimeGraph.

public Graph getBuildTimeGraph() {
    return new Graph(getLastBuild().getTimestamp(), 500, 400) {

        @Override
        protected JFreeChart createGraph() {
            class ChartLabel implements Comparable<ChartLabel> {

                final Run run;

                public ChartLabel(Run r) {
                    this.run = r;
                }

                public int compareTo(ChartLabel that) {
                    return Run.ORDER_BY_DATE.compare(that.run, run);
                }

                @Override
                public boolean equals(Object o) {
                    // on (c instanceof ChartLabel)
                    if (o == null || !ChartLabel.class.isAssignableFrom(o.getClass())) {
                        return false;
                    }
                    ChartLabel that = (ChartLabel) o;
                    return run == that.run;
                }

                public Color getColor() {
                    // TODO: consider gradation. See
                    // http://www.javadrive.jp/java2d/shape/index9.html
                    Result r = run.getResult();
                    if (r == Result.FAILURE)
                        return ColorPalette.RED;
                    else if (r == Result.UNSTABLE)
                        return ColorPalette.YELLOW;
                    else if (r == Result.ABORTED || r == Result.NOT_BUILT)
                        return ColorPalette.GREY;
                    else
                        return ColorPalette.BLUE;
                }

                @Override
                public int hashCode() {
                    return run.hashCode();
                }

                @Override
                public String toString() {
                    String l = run.getDisplayName();
                    if (run instanceof Build) {
                        String s = ((Build) run).getBuiltOnStr();
                        if (s != null)
                            l += ' ' + s;
                    }
                    return l;
                }
            }
            DataSetBuilder<String, ChartLabel> data = new DataSetBuilder<String, ChartLabel>();
            for (Run r : getBuilds()) {
                if (r.isBuilding())
                    continue;
                data.add(((double) r.getDuration()) / (1000 * 60), "min", new ChartLabel(r));
            }
            final CategoryDataset dataset = data.build();
            final JFreeChart chart = // chart
            ChartFactory.createStackedAreaChart(// chart
            null, // unused
            null, // range axis label
            Messages.Job_minutes(), // data
            dataset, // orientation
            PlotOrientation.VERTICAL, // include legend
            false, // tooltips
            true, // urls
            false);
            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();
            ChartUtil.adjustChebyshev(dataset, rangeAxis);
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            StackedAreaRenderer ar = new StackedAreaRenderer2() {

                @Override
                public Paint getItemPaint(int row, int column) {
                    ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
                    return key.getColor();
                }

                @Override
                public String generateURL(CategoryDataset dataset, int row, int column) {
                    ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
                    return String.valueOf(label.run.number);
                }

                @Override
                public String generateToolTip(CategoryDataset dataset, int row, int column) {
                    ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
                    return label.run.getDisplayName() + " : " + label.run.getDurationString();
                }
            };
            plot.setRenderer(ar);
            // 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) DataSetBuilder(hudson.util.DataSetBuilder) StackedAreaRenderer2(hudson.util.StackedAreaRenderer2) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) Graph(hudson.util.Graph) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) JSONObject(net.sf.json.JSONObject)

Example 5 with RectangleInsets

use of org.jfree.ui.RectangleInsets in project series-rest-api by 52North.

the class ChartIoHandler method createPlotArea.

private XYPlot createPlotArea(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    showCrosshairsOnAxes(plot);
    configureDomainAxis(plot);
    showGridlinesOnChart(plot);
    configureTimeAxis(plot);
    configureTitle(chart);
    addNotice(chart);
    return plot;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) RectangleInsets(org.jfree.ui.RectangleInsets)

Aggregations

RectangleInsets (org.jfree.ui.RectangleInsets)28 JFreeChart (org.jfree.chart.JFreeChart)17 Color (java.awt.Color)10 NumberAxis (org.jfree.chart.axis.NumberAxis)10 CategoryPlot (org.jfree.chart.plot.CategoryPlot)9 XYPlot (org.jfree.chart.plot.XYPlot)9 BasicStroke (java.awt.BasicStroke)8 CategoryAxis (org.jfree.chart.axis.CategoryAxis)8 Font (java.awt.Font)5 Paint (java.awt.Paint)4 File (java.io.File)4 SimpleDateFormat (java.text.SimpleDateFormat)4 DateAxis (org.jfree.chart.axis.DateAxis)4 XYDataset (org.jfree.data.xy.XYDataset)4 ShiftedCategoryAxis (hudson.util.ShiftedCategoryAxis)3 ColorScheme (org.baderlab.csplugins.enrichmentmap.style.ColorScheme)3 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)3 StandardBarPainter (org.jfree.chart.renderer.category.StandardBarPainter)3 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)3 CategoryDataset (org.jfree.data.category.CategoryDataset)3