use of org.jfree.chart.renderer.PaintScale in project spf4j by zolyfarkas.
the class Charts method createHeatJFreeChart.
public static JFreeChart createHeatJFreeChart(final String[] dsNames, final double[][] values, final long startTimeMillis, final long stepMillis, final String uom, final String chartName) {
final QuantizedXYZDatasetImpl dataSet = new QuantizedXYZDatasetImpl(dsNames, values, startTimeMillis, stepMillis);
NumberAxis xAxis = new NumberAxis("Time");
xAxis.setStandardTickUnits(dataSet.createXTickUnits());
xAxis.setLowerMargin(0);
xAxis.setUpperMargin(0);
xAxis.setVerticalTickLabels(true);
NumberAxis yAxis = new NumberAxis(uom);
yAxis.setStandardTickUnits(dataSet.createYTickUnits());
yAxis.setLowerMargin(0);
yAxis.setUpperMargin(0);
XYBlockRenderer renderer = new XYBlockRenderer();
PaintScale scale;
if (dataSet.getMinValue() >= dataSet.getMaxValue()) {
if (dataSet.getMinValue() == Double.POSITIVE_INFINITY) {
scale = new InverseGrayScale(0, 1);
} else {
scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue() + 1);
}
} else {
scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue());
}
renderer.setPaintScale(scale);
renderer.setBlockWidth(1);
renderer.setBlockHeight(1);
XYPlot plot = new XYPlot(dataSet, xAxis, yAxis, renderer);
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
plot.setRangeMinorGridlinesVisible(false);
JFreeChart chart = new JFreeChart(chartName, plot);
PaintScaleLegend legend = new PaintScaleLegend(scale, new NumberAxis("Count"));
legend.setMargin(0, 5, 0, 5);
chart.addSubtitle(legend);
chart.removeLegend();
chart.setBackgroundPaint(Color.white);
return chart;
}
Aggregations