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;
}
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;
}
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;
}
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);
}
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());
}
}
Aggregations