Search in sources :

Example 26 with TimeSeries

use of org.jfree.data.time.TimeSeries in project GT by Tencent.

the class AbstractRealTimeLineChart method initDataset.

/**
 * 创建一个二维图表的数据源.
 *
 * @return 数据源对象.
 */
public boolean initDataset(String[] objects, String[] datas) {
    if (objects == null || datas == null || objects.length == 0 || datas.length == 0) {
        return false;
    }
    objectNum = objects.length;
    dataNum = datas.length;
    dataset.removeAllSeries();
    if (datas.length == 1) {
        for (int i = 0; i < objectNum; i++) {
            // 设置曲线的宽度在这里感觉并不太合适
            chart.getXYPlot().getRenderer().setSeriesStroke(i, new BasicStroke(Constant.LINE_WIDTH));
            tsList.add(new TimeSeries(objects[i]));
            tsEnableList.add(true);
            dataset.addSeries(tsList.get(i));
        }
    } else {
        for (int i = 0; i < objectNum; i++) {
            for (int j = 0; j < dataNum; j++) {
                int index = dataNum * i + j;
                // 设置曲线的宽度在这里感觉并不太合适
                chart.getXYPlot().getRenderer().setSeriesStroke(index, new BasicStroke(Constant.LINE_WIDTH));
                tsList.add(new TimeSeries(objects[i] + "_" + datas[j]));
                tsEnableList.add(true);
                dataset.addSeries(tsList.get(index));
            }
        }
    }
    return true;
}
Also used : BasicStroke(java.awt.BasicStroke) TimeSeries(org.jfree.data.time.TimeSeries)

Example 27 with TimeSeries

use of org.jfree.data.time.TimeSeries in project SIMVA-SoS by SESoS.

the class CombinedXYPlotDemo1 method createDataset1.

/**
 * Creates a sample dataset.  You wouldn't normally hard-code the
 * population of a dataset in this way (it would be better to read the
 * values from a file or a database query), but for a self-contained demo
 * this is the least complicated solution.
 *
 * @return The dataset.
 */
private static IntervalXYDataset createDataset1() {
    // create dataset 1...
    TimeSeries series1 = new TimeSeries("Series 1");
    series1.add(new Month(1, 2005), 7627.743);
    series1.add(new Month(2, 2005), 7713.138);
    series1.add(new Month(3, 2005), 6776.939);
    series1.add(new Month(4, 2005), 5764.537);
    series1.add(new Month(5, 2005), 4777.880);
    series1.add(new Month(6, 2005), 4836.496);
    series1.add(new Month(7, 2005), 3887.618);
    series1.add(new Month(8, 2005), 3926.933);
    series1.add(new Month(9, 2005), 4932.710);
    series1.add(new Month(10, 2005), 4027.123);
    series1.add(new Month(11, 2005), 8092.322);
    series1.add(new Month(12, 2005), 8170.414);
    series1.add(new Month(1, 2006), 8196.070);
    series1.add(new Month(2, 2006), 8269.886);
    series1.add(new Month(3, 2006), 5371.156);
    series1.add(new Month(4, 2006), 5355.718);
    series1.add(new Month(5, 2006), 5356.777);
    series1.add(new Month(6, 2006), 8420.042);
    series1.add(new Month(7, 2006), 8444.347);
    series1.add(new Month(8, 2006), 8515.034);
    series1.add(new Month(9, 2006), 8506.974);
    series1.add(new Month(10, 2006), 8584.329);
    series1.add(new Month(11, 2006), 8633.246);
    series1.add(new Month(12, 2006), 8680.224);
    series1.add(new Month(1, 2007), 8707.561);
    return new TimeSeriesCollection(series1);
}
Also used : Month(org.jfree.data.time.Month) TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection)

Example 28 with TimeSeries

use of org.jfree.data.time.TimeSeries in project SIMVA-SoS by SESoS.

the class XYPlotTest method createDataset1.

/**
 * Creates a sample dataset.
 *
 * @return Series 1.
 */
private IntervalXYDataset createDataset1() {
    // create dataset 1...
    TimeSeries series1 = new TimeSeries("Series 1", Day.class);
    series1.add(new Day(1, MonthConstants.MARCH, 2002), 12353.3);
    series1.add(new Day(2, MonthConstants.MARCH, 2002), 13734.4);
    series1.add(new Day(3, MonthConstants.MARCH, 2002), 14525.3);
    series1.add(new Day(4, MonthConstants.MARCH, 2002), 13984.3);
    series1.add(new Day(5, MonthConstants.MARCH, 2002), 12999.4);
    series1.add(new Day(6, MonthConstants.MARCH, 2002), 14274.3);
    series1.add(new Day(7, MonthConstants.MARCH, 2002), 15943.5);
    series1.add(new Day(8, MonthConstants.MARCH, 2002), 14845.3);
    series1.add(new Day(9, MonthConstants.MARCH, 2002), 14645.4);
    series1.add(new Day(10, MonthConstants.MARCH, 2002), 16234.6);
    series1.add(new Day(11, MonthConstants.MARCH, 2002), 17232.3);
    series1.add(new Day(12, MonthConstants.MARCH, 2002), 14232.2);
    series1.add(new Day(13, MonthConstants.MARCH, 2002), 13102.2);
    series1.add(new Day(14, MonthConstants.MARCH, 2002), 14230.2);
    series1.add(new Day(15, MonthConstants.MARCH, 2002), 11235.2);
    TimeSeriesCollection collection = new TimeSeriesCollection(series1);
    return collection;
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) Day(org.jfree.data.time.Day)

Example 29 with TimeSeries

use of org.jfree.data.time.TimeSeries in project pinot by linkedin.

the class AnomalyGraphGenerator method createTimeSeries.

/**
   * Returns data with series 0 = current and 1 = baseline. This method assumes there is exactly one
   * metric in the response data.
   */
private TimeSeriesCollection createTimeSeries(final TimeOnTimeComparisonResponse data) {
    final TimeSeries baseline = new TimeSeries(BASELINE_LABEL);
    final TimeSeries current = new TimeSeries(CURRENT_LABEL);
    for (int i = 0; i < data.getNumRows(); i++) {
        Row row = data.getRow(i);
        // Plot the baseline data as an overlay on the corresponding current data point.
        // long baselineStart = row.getBaselineStart().getMillis();
        long currentStart = row.getCurrentStart().getMillis();
        Date date = new Date(currentStart);
        RegularTimePeriod timePeriod = new Millisecond(date);
        Metric metric = row.getMetrics().get(0);
        baseline.add(timePeriod, metric.getBaselineValue());
        current.add(timePeriod, metric.getCurrentValue());
    }
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(current);
    dataset.addSeries(baseline);
    return dataset;
}
Also used : Millisecond(org.jfree.data.time.Millisecond) TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) Metric(com.linkedin.thirdeye.client.comparison.Row.Metric) Row(com.linkedin.thirdeye.client.comparison.Row) RegularTimePeriod(org.jfree.data.time.RegularTimePeriod) Date(java.sql.Date)

Example 30 with TimeSeries

use of org.jfree.data.time.TimeSeries in project dubbo by alibaba.

the class SimpleMonitorService method createChart.

private static void createChart(String key, String service, String method, String date, String[] types, Map<String, long[]> data, double[] summary, String path) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
    DecimalFormat numberFormat = new DecimalFormat("###,##0.##");
    TimeSeriesCollection xydataset = new TimeSeriesCollection();
    for (int i = 0; i < types.length; i++) {
        String type = types[i];
        TimeSeries timeseries = new TimeSeries(type);
        for (Map.Entry<String, long[]> entry : data.entrySet()) {
            try {
                timeseries.add(new Minute(dateFormat.parse(date + entry.getKey())), entry.getValue()[i]);
            } catch (ParseException e) {
                logger.error(e.getMessage(), e);
            }
        }
        xydataset.addSeries(timeseries);
    }
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("max: " + numberFormat.format(summary[0]) + (summary[1] >= 0 ? " min: " + numberFormat.format(summary[1]) : "") + " avg: " + numberFormat.format(summary[2]) + (summary[3] >= 0 ? " sum: " + numberFormat.format(summary[3]) : ""), toDisplayService(service) + "  " + method + "  " + toDisplayDate(date), key, xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.WHITE);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.GRAY);
    xyplot.setRangeGridlinePaint(Color.GRAY);
    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinesVisible(true);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
    BufferedImage image = jfreechart.createBufferedImage(600, 300);
    try {
        if (logger.isInfoEnabled()) {
            logger.info("write chart: " + path);
        }
        File methodChartFile = new File(path);
        File methodChartDir = methodChartFile.getParentFile();
        if (methodChartDir != null && !methodChartDir.exists()) {
            methodChartDir.mkdirs();
        }
        FileOutputStream output = new FileOutputStream(methodChartFile);
        try {
            ImageIO.write(image, "png", output);
            output.flush();
        } finally {
            output.close();
        }
    } catch (IOException e) {
        logger.warn(e.getMessage(), e);
    }
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) TimeSeries(org.jfree.data.time.TimeSeries) DecimalFormat(java.text.DecimalFormat) IOException(java.io.IOException) JFreeChart(org.jfree.chart.JFreeChart) BufferedImage(java.awt.image.BufferedImage) Minute(org.jfree.data.time.Minute) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) FileOutputStream(java.io.FileOutputStream) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Aggregations

TimeSeries (org.jfree.data.time.TimeSeries)53 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)37 XYPlot (org.jfree.chart.plot.XYPlot)11 Date (java.util.Date)10 JFreeChart (org.jfree.chart.JFreeChart)10 Month (org.jfree.data.time.Month)9 TimeSeriesDataItem (org.jfree.data.time.TimeSeriesDataItem)8 BasicStroke (java.awt.BasicStroke)7 Color (java.awt.Color)7 Map (java.util.Map)7 Day (org.jfree.data.time.Day)6 RegularTimePeriod (org.jfree.data.time.RegularTimePeriod)6 IOException (java.io.IOException)5 List (java.util.List)5 DateAxis (org.jfree.chart.axis.DateAxis)5 NumberAxis (org.jfree.chart.axis.NumberAxis)5 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)5 FixedMillisecond (org.jfree.data.time.FixedMillisecond)5 BufferedImage (java.awt.image.BufferedImage)4 SimpleDateFormat (java.text.SimpleDateFormat)4