Search in sources :

Example 6 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 7 with XYDataset

use of org.jfree.data.xy.XYDataset in project cubrid-manager by CUBRID.

the class MonitorStatisticChart method createChart.

public JFreeChart createChart() {
    final Color backGroundColor = Color.WHITE;
    //final Color backGroundColor = new Color(0xF0F0F0);
    XYDataset dataset = createDataset();
    final int seriesCount = dataset.getSeriesCount();
    chart = ChartFactory.createTimeSeriesChart(chartTitle, timeAxisLabel, valueAxisLabel, dataset, true, true, false);
    chart.setBackgroundPaint(backGroundColor);
    if (!isHasValidData) {
        int red = composite.getBackground().getRed();
        int green = composite.getBackground().getGreen();
        int blue = composite.getBackground().getBlue();
        chart.setBackgroundPaint(new Color(red, green, blue));
        chart.setBackgroundImageAlpha(0.0f);
    }
    XYPlot plot = (XYPlot) chart.getPlot();
    if (!isHasValidData) {
        setNoDataPlot(plot);
    } else {
        setDataPlot(plot);
        chart.getLegend().setBackgroundPaint(Color.white);
    }
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    for (int i = 0; i < seriesCount; i++) {
        renderer.setSeriesPaint(i, colorAr[i % colorAr.length]);
    }
    return chart;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) Color(java.awt.Color) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) XYDataset(org.jfree.data.xy.XYDataset)

Example 8 with XYDataset

use of org.jfree.data.xy.XYDataset in project processdash by dtuma.

the class XYChart method createChart.

/** Create a scatter plot. */
@Override
public JFreeChart createChart() {
    JFreeChart chart;
    String xLabel = null, yLabel = null;
    if (!chromeless) {
        xLabel = Translator.translate(data.getColName(1));
        yLabel = getSetting("yLabel");
        if (yLabel == null && data.numCols() == 2)
            yLabel = data.getColName(2);
        if (yLabel == null)
            yLabel = getSetting("units");
        if (yLabel == null)
            yLabel = "Value";
        yLabel = Translator.translate(yLabel);
    }
    Object autoZero = parameters.get("autoZero");
    boolean firstColumnContainsDate = data.numRows() > 0 && data.numCols() > 0 && data.getData(1, 1) instanceof DateData;
    if (firstColumnContainsDate || parameters.get("xDate") != null) {
        chart = ChartFactory.createTimeSeriesChart(null, xLabel, yLabel, data.xyDataSource(), true, true, false);
        if (firstColumnContainsDate && ((DateData) data.getData(1, 1)).isFormatAsDateOnly())
            chart.getXYPlot().getRenderer().setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getDateInstance(DateFormat.SHORT), NumberFormat.getInstance()));
    } else {
        XYDataset src = data.xyDataSource();
        chart = ChartFactory.createScatterPlot(null, xLabel, yLabel, src, PlotOrientation.VERTICAL, true, true, false);
        if (src instanceof XYToolTipGenerator) {
            chart.getXYPlot().getRenderer().setBaseToolTipGenerator((XYToolTipGenerator) src);
        }
        String trendLine = getParameter("trend");
        if ("none".equalsIgnoreCase(trendLine))
            ;
        else if ("average".equalsIgnoreCase(trendLine))
            addTrendLine(chart, XYDataSourceTrendLine.getAverageLine(src, 0, autoZero != null && !autoZero.equals("y")));
        else
            addTrendLine(chart, XYDataSourceTrendLine.getRegressionLine(src, 0, autoZero != null && !autoZero.equals("y")));
    }
    if (autoZero != null) {
        if (!"x".equals(autoZero))
            ((NumberAxis) chart.getXYPlot().getRangeAxis()).setAutoRangeIncludesZero(true);
        if (!"y".equals(autoZero))
            ((NumberAxis) chart.getXYPlot().getDomainAxis()).setAutoRangeIncludesZero(true);
    }
    if (data.numCols() == 2)
        chart.removeLegend();
    return chart;
}
Also used : StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) DateData(net.sourceforge.processdash.data.DateData) XYDataset(org.jfree.data.xy.XYDataset) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Example 9 with XYDataset

use of org.jfree.data.xy.XYDataset in project cubrid-manager by CUBRID.

the class MonitorStatisticChart method refreshChart.

public void refreshChart(List<StatisticData> statisticDataList) {
    this.statisticDataList = statisticDataList;
    if (chart == null) {
        return;
    }
    int oldDataStatus = isHasValidData ? 1 : 0;
    isHasValidData = false;
    ChartType oldType = chartType;
    XYDataset dataset = createDataset();
    XYPlot plot = chart.getXYPlot();
    int newDataStatus = isHasValidData ? 1 : 0;
    if (!isHasValidData) {
        if (oldDataStatus != newDataStatus) {
            setNoDataPlot(plot);
        }
        plot.setDataset(EMPTY_DATASET);
    } else {
        if (oldDataStatus != newDataStatus) {
            setDataPlot(plot);
        }
        if (chartType != oldType) {
            plot.getRangeAxis().setRange(rangMin, rangMax);
        }
        plot.setDataset(dataset);
    }
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) ChartType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.ChartType) XYDataset(org.jfree.data.xy.XYDataset)

Example 10 with XYDataset

use of org.jfree.data.xy.XYDataset in project zm-mailbox by Zimbra.

the class ChartUtil method hasData.

private boolean hasData(JFreeChart chart) {
    if (chart == null) {
        return false;
    }
    XYPlot plot = chart.getXYPlot();
    XYDataset data = plot.getDataset();
    int numPoints = 0;
    for (int i = 0; i < data.getSeriesCount(); i++) {
        numPoints += data.getItemCount(i);
    }
    if (numPoints == 0) {
        return false;
    }
    return true;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) XYDataset(org.jfree.data.xy.XYDataset)

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