Search in sources :

Example 31 with TimeSeries

use of org.jfree.data.time.TimeSeries in project cubrid-manager by CUBRID.

the class MonitorStatisticChart method createDataset.

private XYDataset createDataset() {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    if (statisticDataList == null) {
        return dataset;
    }
    double maxForRang = 0;
    List<StatisticData> dataItemWithoutDataList = new ArrayList<StatisticData>();
    TimeType timeType = null;
    Date current = new Date();
    long interalMillisecs = 0;
    for (StatisticData statisticData : statisticDataList) {
        if (statisticData == null) {
            continue;
        }
        MetricType metricType = MetricType.getEnumByMetric(statisticData.getMetric());
        if (metricType == null) {
            continue;
        }
        int size = statisticData.getData().size();
        if (size == 0) {
            dataItemWithoutDataList.add(statisticData);
            continue;
        } else if (dataSize == 0) {
            //record data size for build invalid data
            dataSize = size;
        }
        //check data type, record 'isHasValidData = true'
        if (!isHasValidData) {
            isHasValidData = true;
            chartType = getChartType(statisticData.getMetric());
            if (chartType == ChartType.PERCENT) {
                rangMax = 100;
            }
            String dateType = statisticData.getDtype();
            timeType = TimeType.getEnumByType(dateType);
            //CMS return -1 for invalid data, so for invalid data(<0), display as -1.
            switch(timeType) {
                case DAILY:
                    interalMillisecs = 1000 * 60 * 60 * 24 / size;
                    break;
                case WEEKLY:
                    interalMillisecs = 1000 * 60 * 60;
                    break;
                case MONTHLY:
                    interalMillisecs = 1000 * 60 * 60;
                    break;
                case YEARLY:
                    interalMillisecs = 1000 * 60 * 60 * 24;
                    break;
                default:
                    break;
            }
        }
        TimeSeries series = null;
        if (isDetailView) {
            series = new TimeSeries(statisticData.getDescription(isMultiHost));
        } else {
            series = new TimeSeries(statisticData.getSimpleDescription(isMultiHost));
        }
        Date point = (Date) current.clone();
        long curMillisecs = current.getTime();
        int count = 0;
        int max = 0;
        int min = 0;
        boolean isInitMinVal = false;
        for (int val : statisticData.getData()) {
            point.setTime(curMillisecs - (size - count) * interalMillisecs);
            switch(timeType) {
                case DAILY:
                    if (val < 0) {
                        series.add(new Second(point), -1);
                    } else {
                        series.add(new Second(point), val / 100);
                    }
                    break;
                case WEEKLY:
                    if (val < 0) {
                        series.add(new Hour(point), -1);
                    } else {
                        series.add(new Hour(point), val / 100);
                    }
                    break;
                case MONTHLY:
                    if (val < 0) {
                        series.add(new Hour(point), -1);
                    } else {
                        series.add(new Hour(point), val / 100);
                    }
                    break;
                case YEARLY:
                    if (val < 0) {
                        series.add(new Day(point), -1);
                    } else {
                        series.add(new Day(point), val / 100);
                    }
                    break;
                default:
                    break;
            }
            if (chartType != ChartType.PERCENT && val > maxForRang) {
                maxForRang = val;
            }
            if (!isInitMinVal && val >= 0) {
                min = val;
                isInitMinVal = true;
            }
            if (val > max) {
                max = val;
            }
            if (val < min && val >= 0) {
                min = val;
            }
            count++;
        }
        maxValueMap.put(statisticData, max / 100d);
        minValueMap.put(statisticData, min / 100d);
        dataset.addSeries(series);
    }
    if (!isHasValidData) {
        return dataset;
    }
    if (chartType != ChartType.PERCENT) {
        decideRangMax(maxForRang / 100);
    }
    /*[TOOLS-3742] Build invalid data for StatisticData which has no data*/
    buildInvalidData(dataset, timeType, dataItemWithoutDataList, current, interalMillisecs);
    if (isDetailView) {
        chartTitle = Messages.monStatisticDetailChartTitle;
        timeAxisLabel = Messages.lblChartTime;
        valueAxisLabel = Messages.lblChartValue;
        switch(chartType) {
            case PERCENT:
                valueAxisLabel += " (%)";
                break;
            case MEMORY:
            case SPACE:
                valueAxisLabel += " (MB)";
                break;
            case OTHERS:
                break;
            default:
                break;
        }
    }
    return dataset;
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) Hour(org.jfree.data.time.Hour) MetricType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.MetricType) ArrayList(java.util.ArrayList) StatisticData(com.cubrid.cubridmanager.core.monstatistic.model.StatisticData) Date(java.util.Date) TimeType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.TimeType) Second(org.jfree.data.time.Second) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) Day(org.jfree.data.time.Day)

Example 32 with TimeSeries

use of org.jfree.data.time.TimeSeries in project cubrid-manager by CUBRID.

the class ChartCompositePart method createChart.

/**
	 * Create the chart
	 *
	 * @return the instance of JFreeChart
	 */
private JFreeChart createChart() {
    timeseriescollection = new TimeSeriesCollection();
    seriesMap = new TreeMap<String, TimeSeries>();
    xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
    int number = 0;
    for (Map.Entry<String, String> entry : valueMap.entrySet()) {
        String key = entry.getKey();
        TimeSeries series = new TimeSeries(key);
        seriesMap.put(key, series);
        if (settingMap.get(key).isChecked()) {
            timeseriescollection.addSeries(series);
            RGB seriesRgb = settingMap.get(key).getSeriesRgb();
            float width = settingMap.get(key).getWidth();
            Color color = new Color(seriesRgb.red, seriesRgb.green, seriesRgb.blue);
            xylineandshaperenderer.setSeriesPaint(number, color);
            xylineandshaperenderer.setSeriesStroke(number, new BasicStroke(width, 0, 2));
            number++;
        }
    }
    DateAxis dateaxis = new DateAxis("");
    NumberAxis numberaxis = new NumberAxis("");
    dateaxis.setTickLabelFont(new Font("SansSerif", 0, 10));
    dateaxis.setLabelFont(new Font("SansSerif", 0, 7));
    XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer);
    RectangleInsets rectangleInsets = new RectangleInsets();
    xyplot.setAxisOffset(rectangleInsets);
    xyplot.setDomainGridlineStroke(new BasicStroke(0.4f));
    xyplot.setRangeGridlineStroke(new BasicStroke(0.4f));
    xyplot.setOutlineVisible(false);
    xyplot.setBackgroundPaint(Color.BLACK);
    xyplot.setDomainGridlinePaint(new Color(0, 128, 64));
    xyplot.setRangeGridlinePaint(new Color(0, 128, 64));
    dateaxis.setFixedAutoRange(300000d);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setTickLabelsVisible(true);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLowerMargin(0.01D);
    numberaxis.setUpperMargin(0.01D);
    JFreeChart chart = new JFreeChart(chartTitle, new Font("SansSerif", 1, 15), xyplot, false);
    chart.setBorderVisible(false);
    chart.setBorderStroke(new BasicStroke(0.0f));
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) DateAxis(org.jfree.chart.axis.DateAxis) TimeSeries(org.jfree.data.time.TimeSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) CommonUITool.trimPaintColor(com.cubrid.common.ui.spi.util.CommonUITool.trimPaintColor) RGB(org.eclipse.swt.graphics.RGB) Font(java.awt.Font) JFreeChart(org.jfree.chart.JFreeChart) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) RectangleInsets(org.jfree.ui.RectangleInsets) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 33 with TimeSeries

use of org.jfree.data.time.TimeSeries in project cubrid-manager by CUBRID.

the class ReplicationMonitorViewPart method createChart.

/**
	 * Create chart unit
	 * 
	 * @return chart
	 */
private JFreeChart createChart() {
    //create data set
    replTimeSeries = new TimeSeries(Messages.msgDelayValue + "    ");
    replTimeSeries.setMaximumItemAge(2592000);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(replTimeSeries);
    //create X axis
    DateAxis dateaxis = new DateAxis(Messages.msgSlaveTimes);
    dateaxis.setTickLabelFont(new Font("SansSerif", 0, 10));
    dateaxis.setLabelFont(new Font("SansSerif", 0, 7));
    dateaxis.setFixedAutoRange(300000d);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setTickLabelsVisible(true);
    //create Y axis
    NumberAxis numberaxis = new NumberAxis(Messages.msgDelayValue);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //create display model
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, true);
    xylineandshaperenderer.setSeriesPaint(0, new Color(146, 208, 80));
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(2F, 0, 2));
    XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer);
    //set backcolor of grid
    xyplot.setBackgroundPaint(Color.BLACK);
    //set vertical line color of grid
    xyplot.setDomainGridlinePaint(new Color(130, 130, 130));
    //set horizontal line color of grid
    xyplot.setRangeGridlinePaint(new Color(130, 130, 130));
    xyplot.setAxisOffset(new RectangleInsets(0D, 0D, 0D, 10D));
    JFreeChart chart = new JFreeChart(Messages.titlePerformancePart, new Font("SansSerif", 1, 15), xyplot, true);
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) DateAxis(org.jfree.chart.axis.DateAxis) TimeSeries(org.jfree.data.time.TimeSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) RectangleInsets(org.jfree.ui.RectangleInsets) Font(java.awt.Font) JFreeChart(org.jfree.chart.JFreeChart)

Example 34 with TimeSeries

use of org.jfree.data.time.TimeSeries in project incubator-dubbo-ops by apache.

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)

Example 35 with TimeSeries

use of org.jfree.data.time.TimeSeries in project pentaho-platform by pentaho.

the class TimeSeriesCollectionChartDefinition method setDataByRow.

private void setDataByRow(final IPentahoResultSet data) {
    // TODO Make this routine MDX friendly
    if (data == null) {
        // $NON-NLS-1$
        noDataMessage = Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE");
        // No data so we've got nothing to set
        return;
    // TODO come up with some sort of error strategy here.
    }
    Class timePeriodClass = TimeSeriesCollectionChartDefinition.getTimePeriodClass(getDomainPeriodType());
    Object[] rowData = data.next();
    while (rowData != null) {
        String seriesName = (String) rowData[0];
        TimeSeries wrkSeries = new TimeSeries(seriesName, timePeriodClass);
        for (int column = 1; column < rowData.length - 1; column = column + 2) {
            Date keyDate = getValidDate(rowData[column]);
            TimeSeriesDataItem timeSeriesDataItem = new TimeSeriesDataItem(RegularTimePeriod.createInstance(timePeriodClass, keyDate, RegularTimePeriod.DEFAULT_TIME_ZONE), ((Number) rowData[column + 1]).doubleValue());
            wrkSeries.add(timeSeriesDataItem);
        }
        addSeries(wrkSeries);
        rowData = data.next();
    }
    if ((data.getRowCount() > 0) && (this.getSeriesCount() <= 0)) {
        // $NON-NLS-1$
        noDataMessage = Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT");
    }
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) Paint(java.awt.Paint) Date(java.util.Date)

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