Search in sources :

Example 1 with XYPlot

use of org.jfree.chart.plot.XYPlot 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 2 with XYPlot

use of org.jfree.chart.plot.XYPlot 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)

Example 3 with XYPlot

use of org.jfree.chart.plot.XYPlot in project libresonic by Libresonic.

the class StatusChartController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String type = request.getParameter("type");
    int index = Integer.parseInt(request.getParameter("index"));
    List<TransferStatus> statuses = Collections.emptyList();
    if ("stream".equals(type)) {
        statuses = statusService.getAllStreamStatuses();
    } else if ("download".equals(type)) {
        statuses = statusService.getAllDownloadStatuses();
    } else if ("upload".equals(type)) {
        statuses = statusService.getAllUploadStatuses();
    }
    if (index < 0 || index >= statuses.size()) {
        return null;
    }
    TransferStatus status = statuses.get(index);
    TimeSeries series = new TimeSeries("Kbps", Millisecond.class);
    TransferStatus.SampleHistory history = status.getHistory();
    long to = System.currentTimeMillis();
    long from = to - status.getHistoryLengthMillis();
    Range range = new DateRange(from, to);
    if (!history.isEmpty()) {
        TransferStatus.Sample previous = history.get(0);
        for (int i = 1; i < history.size(); i++) {
            TransferStatus.Sample sample = history.get(i);
            long elapsedTimeMilis = sample.getTimestamp() - previous.getTimestamp();
            long bytesStreamed = Math.max(0L, sample.getBytesTransfered() - previous.getBytesTransfered());
            double kbps = (8.0 * bytesStreamed / 1024.0) / (elapsedTimeMilis / 1000.0);
            series.addOrUpdate(new Millisecond(new Date(sample.getTimestamp())), kbps);
            previous = sample;
        }
    }
    // Compute moving average.
    series = MovingAverage.createMovingAverage(series, "Kbps", 20000, 5000);
    // Find min and max values.
    double min = 100;
    double max = 250;
    for (Object obj : series.getItems()) {
        TimeSeriesDataItem item = (TimeSeriesDataItem) obj;
        double value = item.getValue().doubleValue();
        if (item.getPeriod().getFirstMillisecond() > from) {
            min = Math.min(min, value);
            max = Math.max(max, value);
        }
    }
    // Add 10% to max value.
    max *= 1.1D;
    // Subtract 10% from min value.
    min *= 0.9D;
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    XYItemRenderer renderer = plot.getRendererForDataset(dataset);
    renderer.setSeriesPaint(0, Color.blue.darker());
    renderer.setSeriesStroke(0, new BasicStroke(2f));
    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);
    chart.setBackgroundPaint(bgColor);
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setRange(range);
    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setRange(new Range(min, max));
    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);
    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, IMAGE_HEIGHT);
    return null;
}
Also used : Range(org.jfree.data.Range) Date(java.util.Date) JFreeChart(org.jfree.chart.JFreeChart) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) TransferStatus(org.libresonic.player.domain.TransferStatus) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with XYPlot

use of org.jfree.chart.plot.XYPlot in project cubrid-manager by CUBRID.

the class DbDashboardHistoryViewPart method loadDatabaseChart.

/**
	 * Load an instance of ChartCompositePart stand for database monitor info
	 *
	 * @param parent an instance of Composite
	 */
private void loadDatabaseChart(Composite parent) {
    dbStatComp = new Composite(parent, SWT.NULL);
    dbStatComp.setLayout(new GridLayout());
    dbStatComp.setLayoutData(new GridData(GridData.FILL_BOTH));
    Group dbGrp = new Group(dbStatComp, SWT.NONE);
    dbGrp.setText(Messages.dbDatabaseStatusSeriesGroupName);
    GridLayout layoutGrp = new GridLayout();
    layoutGrp.verticalSpacing = 0;
    layoutGrp.horizontalSpacing = 0;
    layoutGrp.marginLeft = 0;
    layoutGrp.marginRight = 0;
    layoutGrp.marginTop = 0;
    layoutGrp.marginBottom = 0;
    dbGrp.setLayout(layoutGrp);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    dbGrp.setLayoutData(gridData);
    DbStatDumpData dbStatDumpData = new DbStatDumpData();
    TreeMap<String, String> map = convertMapKey(dbStatDumpData.getDiagStatusResultMap());
    dbStatChartPart = new ChartCompositePart(dbGrp, map);
    for (Map.Entry<String, String> entry : map.entrySet()) {
        String key = entry.getKey();
        ShowSetting showSetting = dbStatChartPart.getSettingMap().get(key);
        ShowSettingMatching.match(key, showSetting, MonitorType.DATABASE);
    }
    dbStatChartPart.loadContent();
    JFreeChart chart = (JFreeChart) dbStatChartPart.getChart();
    chart.setBorderVisible(false);
    XYPlot xyplot = (XYPlot) dbStatChartPart.getChart().getPlot();
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setFixedAutoRange(300000d);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setVisible(true);
    xyplot.getRangeAxis().setVisible(true);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    renderer.setURLGenerator(null);
    renderer.setBaseToolTipGenerator(null);
}
Also used : Group(org.eclipse.swt.widgets.Group) DateAxis(org.jfree.chart.axis.DateAxis) Composite(org.eclipse.swt.widgets.Composite) HistoryComposite(com.cubrid.cubridmanager.ui.monitoring.editor.internal.HistoryComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) DbStatDumpData(com.cubrid.cubridmanager.core.monitoring.model.DbStatDumpData) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) JFreeChart(org.jfree.chart.JFreeChart) GridLayout(org.eclipse.swt.layout.GridLayout) XYPlot(org.jfree.chart.plot.XYPlot) GridData(org.eclipse.swt.layout.GridData) ShowSetting(com.cubrid.cubridmanager.ui.monitoring.editor.internal.ShowSetting) ChartCompositePart(com.cubrid.cubridmanager.ui.monitoring.editor.internal.ChartCompositePart) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 5 with XYPlot

use of org.jfree.chart.plot.XYPlot in project cubrid-manager by CUBRID.

the class DbDashboardHistoryViewPart method fireChartSetting.

/**
	 * This method is responsible for preparing data for ChartSettingDlg and
	 * dealing with the results of chartSettingDlg
	 *
	 */
private void fireChartSetting() {
    ChartSettingDlg chartSettingDlg = new ChartSettingDlg(composite.getShell());
    chartSettingDlg.setHasTitlSetting(false);
    chartSettingDlg.setHasHistoryPath(true);
    chartSettingDlg.setHasAxisSetting(false);
    chartSettingDlg.setHasChartSelection(true);
    // plot appearance
    XYPlot dbStatplot = dbStatChartPart.getChart().getXYPlot();
    String plotBgColor = trimPaintColor(dbStatplot.getBackgroundPaint().toString());
    String plotDomainGridColor = trimPaintColor(dbStatplot.getDomainGridlinePaint().toString());
    String plotRangGridColor = trimPaintColor(dbStatplot.getRangeGridlinePaint().toString());
    chartSettingDlg.setPlotBgColor(plotBgColor);
    chartSettingDlg.setPlotDomainGridColor(plotDomainGridColor);
    chartSettingDlg.setPlotRangGridColor(plotRangGridColor);
    // series
    chartSettingDlg.setSettingMap(dbStatChartPart.getSettingMap());
    // chart selection
    chartSettingDlg.setChartSelectionLst(getSelectedCharts());
    // history path
    chartSettingDlg.setHistoryPath(historyPath);
    chartSettingDlg.setHistoryFileName(historyFileName);
    if (chartSettingDlg.open() == Dialog.OK) {
        // plot appearance
        plotBgColor = chartSettingDlg.getPlotBgColor();
        plotDomainGridColor = chartSettingDlg.getPlotDomainGridColor();
        plotRangGridColor = chartSettingDlg.getPlotRangGridColor();
        //SeruesPlot
        XYPlot cpuSeriesPlot = (XYPlot) cpuChart.getSeriesChart().getPlot();
        XYPlot memorySeriesPlot = (XYPlot) memoryChart.getSeriesChart().getPlot();
        XYPlot delaySeriesPlot = (XYPlot) delayChart.getSeriesChart().getPlot();
        XYPlot countSeriesPlot = (XYPlot) countChart.getSeriesChart().getPlot();
        // history path
        String newHistoryPath = chartSettingDlg.getHistoryPath();
        isChangedHistoryPath = historyPath.equals(newHistoryPath) ? false : true;
        if (isChangedHistoryPath) {
            historyPath = newHistoryPath;
            historyFileHelp.setHistoryPath(historyPath);
        }
        int red = 0;
        int green = 0;
        int blue = 0;
        //background
        red = getColorElem(plotBgColor, 0);
        green = getColorElem(plotBgColor, 1);
        blue = getColorElem(plotBgColor, 2);
        Color bgColor = new Color(red, green, blue);
        dbStatplot.setBackgroundPaint(bgColor);
        //cpu chart
        cpuSeriesPlot.setBackgroundPaint(bgColor);
        //memoryChart
        memorySeriesPlot.setBackgroundPaint(bgColor);
        //delayChart
        delaySeriesPlot.setBackgroundPaint(bgColor);
        //countChart;
        countSeriesPlot.setBackgroundPaint(bgColor);
        //DomainGridColor
        //db Chart
        red = getColorElem(plotDomainGridColor, 0);
        green = getColorElem(plotDomainGridColor, 1);
        blue = getColorElem(plotDomainGridColor, 2);
        Color domainGridlineColor = new Color(red, green, blue);
        dbStatplot.setDomainGridlinePaint(domainGridlineColor);
        //cpu chart
        cpuSeriesPlot.setDomainGridlinePaint(domainGridlineColor);
        //memoryChart
        memorySeriesPlot.setDomainGridlinePaint(domainGridlineColor);
        //delayChart
        delaySeriesPlot.setDomainGridlinePaint(domainGridlineColor);
        //countChart;
        countSeriesPlot.setDomainGridlinePaint(domainGridlineColor);
        //RangeGridColor
        red = getColorElem(plotRangGridColor, 0);
        green = getColorElem(plotRangGridColor, 1);
        blue = getColorElem(plotRangGridColor, 2);
        Color rangeGridColor = new Color(red, green, blue);
        dbStatplot.setRangeGridlinePaint(rangeGridColor);
        //cpu chart
        cpuSeriesPlot.setRangeGridlinePaint(rangeGridColor);
        //memoryChart
        memorySeriesPlot.setRangeGridlinePaint(rangeGridColor);
        //delayChart
        delaySeriesPlot.setRangeGridlinePaint(rangeGridColor);
        //countChart;
        countSeriesPlot.setRangeGridlinePaint(rangeGridColor);
        dbStatChartPart.setSettingMap(chartSettingDlg.getSettingMap());
        dbStatChartPart.updateSettingSeries();
        //chart Selection
        fireChartSelection(chartSettingDlg.getChartSelectionLst());
    }
}
Also used : ChartSettingDlg(com.cubrid.cubridmanager.ui.monitoring.editor.internal.ChartSettingDlg) XYPlot(org.jfree.chart.plot.XYPlot) Color(java.awt.Color) CommonUITool.trimPaintColor(com.cubrid.common.ui.spi.util.CommonUITool.trimPaintColor)

Aggregations

XYPlot (org.jfree.chart.plot.XYPlot)160 JFreeChart (org.jfree.chart.JFreeChart)98 NumberAxis (org.jfree.chart.axis.NumberAxis)49 Color (java.awt.Color)43 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)35 ValueAxis (org.jfree.chart.axis.ValueAxis)34 DateAxis (org.jfree.chart.axis.DateAxis)33 XYDataset (org.jfree.data.xy.XYDataset)30 SimpleDateFormat (java.text.SimpleDateFormat)22 XYSeries (org.jfree.data.xy.XYSeries)22 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)21 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)21 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)18 BasicStroke (java.awt.BasicStroke)16 Font (java.awt.Font)16 ChartPanel (org.jfree.chart.ChartPanel)16 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)16 DecimalFormat (java.text.DecimalFormat)13 Map (java.util.Map)13 LegendTitle (org.jfree.chart.title.LegendTitle)13