Search in sources :

Example 1 with XYDataset

use of org.jfree.data.xy.XYDataset 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 XYDataset

use of org.jfree.data.xy.XYDataset 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 XYDataset

use of org.jfree.data.xy.XYDataset in project Openfire by igniterealtime.

the class GraphEngine method generateSparklineAreaChart.

/**
     * Generates a SparkLine Time Area Chart.
     * @param key
     * @param stats
     * @param startTime
     * @param endTime
     * @return chart
     */
private JFreeChart generateSparklineAreaChart(String key, String color, Statistic[] stats, long startTime, long endTime, int dataPoints) {
    Color backgroundColor = getBackgroundColor();
    XYDataset dataset = populateData(key, stats, startTime, endTime, dataPoints);
    JFreeChart chart = ChartFactory.createXYAreaChart(// chart title
    null, // xaxis label
    null, // yaxis label
    null, // data
    dataset, PlotOrientation.VERTICAL, // include legend
    false, // tooltips?
    false, // URLs?
    false);
    chart.setBackgroundPaint(backgroundColor);
    chart.setBorderVisible(false);
    chart.setBorderPaint(null);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(1.0f);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(backgroundColor);
    plot.setRangeGridlinesVisible(false);
    GraphDefinition graphDef = GraphDefinition.getDefinition(color);
    Color plotColor = graphDef.getInlineColor(0);
    plot.getRenderer().setSeriesPaint(0, plotColor);
    plot.getRenderer().setBaseItemLabelsVisible(false);
    plot.getRenderer().setBaseOutlinePaint(backgroundColor);
    plot.setOutlineStroke(null);
    plot.setDomainGridlinePaint(null);
    NumberAxis xAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();
    xAxis.setLabel(null);
    xAxis.setTickLabelsVisible(true);
    xAxis.setTickMarksVisible(true);
    xAxis.setAxisLineVisible(false);
    xAxis.setNegativeArrowVisible(false);
    xAxis.setPositiveArrowVisible(false);
    xAxis.setVisible(false);
    NumberAxis yAxis = (NumberAxis) chart.getXYPlot().getRangeAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setAxisLineVisible(false);
    yAxis.setNegativeArrowVisible(false);
    yAxis.setPositiveArrowVisible(false);
    yAxis.setVisible(false);
    return chart;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYDataset(org.jfree.data.xy.XYDataset) JFreeChart(org.jfree.chart.JFreeChart)

Example 4 with XYDataset

use of org.jfree.data.xy.XYDataset in project Openfire by igniterealtime.

the class GraphEngine method generateChart.

/**
     * Creates a chart.
     *
     * @param key
     * @param width
     * @param height
     * @param startTime
     * @param endTime
     * @param dataPoints
     * @return
     * @throws IOException
     */
public JFreeChart generateChart(String key, int width, int height, String color, long startTime, long endTime, int dataPoints) throws IOException {
    Statistic[] def = statsViewer.getStatistic(key);
    if (def == null) {
        return null;
    }
    XYDataset data = populateData(key, def, startTime, endTime, dataPoints);
    if (data == null) {
        return null;
    }
    JFreeChart chart;
    switch(def[0].getStatType()) {
        case count:
            chart = createTimeBarChart(null, color, def[0].getUnits(), data);
            break;
        default:
            chart = createTimeAreaChart(null, color, def[0].getUnits(), data);
    }
    return chart;
}
Also used : Statistic(org.jivesoftware.openfire.stats.Statistic) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYDataset(org.jfree.data.xy.XYDataset) JFreeChart(org.jfree.chart.JFreeChart)

Example 5 with XYDataset

use of org.jfree.data.xy.XYDataset 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)

Aggregations

XYDataset (org.jfree.data.xy.XYDataset)11 XYPlot (org.jfree.chart.plot.XYPlot)8 File (java.io.File)4 SimpleDateFormat (java.text.SimpleDateFormat)4 RectangleInsets (org.jfree.ui.RectangleInsets)4 JFreeChart (org.jfree.chart.JFreeChart)3 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)2 ChartType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.ChartType)1 Color (java.awt.Color)1 JPopupMenu (javax.swing.JPopupMenu)1 DateData (net.sourceforge.processdash.data.DateData)1 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)1 XYToolTipGenerator (org.jfree.chart.labels.XYToolTipGenerator)1 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)1 Statistic (org.jivesoftware.openfire.stats.Statistic)1