Search in sources :

Example 1 with PaintScale

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;
}
Also used : PaintScale(org.jfree.chart.renderer.PaintScale) PaintScaleLegend(org.jfree.chart.title.PaintScaleLegend) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) XYBlockRenderer(org.jfree.chart.renderer.xy.XYBlockRenderer) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 XYPlot (org.jfree.chart.plot.XYPlot)1 PaintScale (org.jfree.chart.renderer.PaintScale)1 XYBlockRenderer (org.jfree.chart.renderer.xy.XYBlockRenderer)1 PaintScaleLegend (org.jfree.chart.title.PaintScaleLegend)1