use of org.jfree.chart.axis.ValueAxis in project series-rest-api by 52North.
the class ChartIoHandler method configureDomainAxis.
private void configureDomainAxis(XYPlot plot) {
ValueAxis domainAxis = plot.getDomainAxis();
domainAxis.setTickLabelFont(LabelConstants.FONT_LABEL);
domainAxis.setLabelFont(LabelConstants.FONT_LABEL);
domainAxis.setTickLabelPaint(LabelConstants.COLOR);
domainAxis.setLabelPaint(LabelConstants.COLOR);
}
use of org.jfree.chart.axis.ValueAxis 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.axis.ValueAxis in project jgnash by ccavanaugh.
the class SecurityHighLowChart method createHighLowChart.
private static JFreeChart createHighLowChart(String title, String timeAxisLabel, String valueAxisLabel, AbstractXYDataset data, boolean legend) {
ValueAxis timeAxis = new DateAxis(timeAxisLabel);
NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
valueAxis.setAutoRangeIncludesZero(false);
HighLowRenderer renderer = new HighLowRenderer();
renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());
XYPlot plot = new XYPlot(data, timeAxis, valueAxis, renderer);
return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
}
use of org.jfree.chart.axis.ValueAxis in project dhis2-core by dhis2.
the class DefaultChartService method getJFreeChart.
/**
* Returns a JFreeChart of type defined in the chart argument.
*/
private JFreeChart getJFreeChart(BaseChart chart) {
final CategoryDataset[] dataSets = getCategoryDataSet(chart);
final CategoryDataset dataSet = dataSets[0];
final BarRenderer barRenderer = getBarRenderer();
final LineAndShapeRenderer lineRenderer = getLineRenderer();
// ---------------------------------------------------------------------
// Plot
// ---------------------------------------------------------------------
CategoryPlot plot = null;
if (chart.isType(ChartType.LINE)) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), lineRenderer);
plot.setOrientation(PlotOrientation.VERTICAL);
} else if (chart.isType(ChartType.COLUMN)) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
plot.setOrientation(PlotOrientation.VERTICAL);
} else if (chart.isType(ChartType.BAR)) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
plot.setOrientation(PlotOrientation.HORIZONTAL);
} else if (chart.isType(ChartType.AREA)) {
return getStackedAreaChart(chart, dataSet);
} else if (chart.isType(ChartType.PIE)) {
return getMultiplePieChart(chart, dataSets);
} else if (chart.isType(ChartType.STACKED_COLUMN)) {
return getStackedBarChart(chart, dataSet, false);
} else if (chart.isType(ChartType.STACKED_BAR)) {
return getStackedBarChart(chart, dataSet, true);
} else if (chart.isType(ChartType.RADAR)) {
return getRadarChart(chart, dataSet);
} else if (chart.isType(ChartType.GAUGE)) {
Number number = dataSet.getValue(0, 0);
ValueDataset valueDataSet = new DefaultValueDataset(number);
return getGaugeChart(chart, valueDataSet);
} else {
throw new IllegalArgumentException("Illegal or no chart type: " + chart.getType());
}
if (chart.isRegression()) {
plot.setDataset(1, dataSets[1]);
plot.setRenderer(1, lineRenderer);
}
JFreeChart jFreeChart = new JFreeChart(chart.getName(), TITLE_FONT, plot, !chart.isHideLegend());
setBasicConfig(jFreeChart, chart);
if (chart.isTargetLine()) {
plot.addRangeMarker(getMarker(chart.getTargetLineValue(), chart.getTargetLineLabel()));
}
if (chart.isBaseLine()) {
plot.addRangeMarker(getMarker(chart.getBaseLineValue(), chart.getBaseLineLabel()));
}
if (chart.isHideSubtitle()) {
jFreeChart.addSubtitle(getSubTitle(chart));
}
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
// ---------------------------------------------------------------------
// Category label positions
// ---------------------------------------------------------------------
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
domainAxis.setLabel(chart.getDomainAxisLabel());
ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setLabel(chart.getRangeAxisLabel());
return jFreeChart;
}
use of org.jfree.chart.axis.ValueAxis in project processdash by dtuma.
the class CGIChartBase method setupCategoryChart.
protected void setupCategoryChart(JFreeChart chart) {
if (!(chart.getPlot() instanceof CategoryPlot))
return;
CategoryPlot cp = chart.getCategoryPlot();
CategoryAxis catAxis = cp.getDomainAxis();
ValueAxis otherAxis = cp.getRangeAxis();
if (!chromeless) {
String catAxisLabel = data.getColName(0);
if (catAxisLabel == null)
catAxisLabel = Translator.translate("Project/Task");
String otherAxisLabel = Translator.translate(getSetting("units"));
if ((otherAxisLabel == null || otherAxisLabel.length() == 0) && data.numCols() == 1)
otherAxisLabel = data.getColName(1);
if (otherAxisLabel == null)
otherAxisLabel = Translator.translate("Value");
String catLabels = getParameter("categoryLabels");
catAxis.setLabel(catAxisLabel);
otherAxis.setLabel(otherAxisLabel);
if ("vertical".equalsIgnoreCase(catLabels))
catAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
else if ("none".equalsIgnoreCase(catLabels))
catAxis.setTickLabelsVisible(false);
}
if (data.numCols() == 1 && getParameter("noSkipLegend") == null) {
chart.removeLegend();
chart.getPlot().setInsets(new RectangleInsets(5, 2, 2, 5));
}
}
Aggregations