Search in sources :

Example 1 with XYBlockRenderer

use of org.jfree.chart.renderer.xy.XYBlockRenderer in project cytoscape-impl by cytoscape.

the class HeatMapLayer method createChart.

@Override
protected JFreeChart createChart(final XYZDataset dataset) {
    final PlotOrientation plotOrientation = orientation == Orientation.HORIZONTAL ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL;
    final SymbolAxis xAxis = new SymbolAxis(null, xLabels);
    xAxis.setVisible(showDomainAxis);
    xAxis.setAxisLineVisible(false);
    xAxis.setTickMarksVisible(false);
    xAxis.setTickLabelFont(xAxis.getLabelFont().deriveFont(axisFontSize));
    xAxis.setTickLabelPaint(axisColor);
    xAxis.setVerticalTickLabels(domainLabelPosition != LabelPosition.STANDARD);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    final SymbolAxis yAxis = new SymbolAxis(null, yLabels);
    yAxis.setVisible(showRangeAxis);
    yAxis.setAxisLineVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setTickLabelFont(yAxis.getLabelFont().deriveFont(axisFontSize));
    yAxis.setTickLabelPaint(axisColor);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setInverted(true);
    final XYBlockRenderer renderer = new XYBlockRenderer();
    if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
        final int colorsSize = colors != null ? colors.size() : 0;
        Color upperColor = colorsSize > 0 ? colors.get(0) : Color.BLUE;
        Color zeroColor = colorsSize > 1 ? colors.get(1) : Color.WHITE;
        Color lowerColor = colorsSize > 2 ? colors.get(2) : Color.RED;
        Color nanColor = colorsSize > 3 ? colors.get(3) : Color.GRAY;
        final ColorScale scale = new ColorScale(range.get(0), range.get(1), lowerColor, zeroColor, upperColor, nanColor);
        renderer.setPaintScale(scale);
    }
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setDomainAxis(xAxis);
    plot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setBackgroundPaint(TRANSPARENT_COLOR);
    plot.setInsets(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    plot.setOrientation(plotOrientation);
    final JFreeChart chart = new JFreeChart(null, plot);
    chart.removeLegend();
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(TRANSPARENT_COLOR);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    return chart;
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) XYPlot(org.jfree.chart.plot.XYPlot) Color(java.awt.Color) XYBlockRenderer(org.jfree.chart.renderer.xy.XYBlockRenderer) ColorScale(org.cytoscape.ding.internal.charts.util.ColorScale) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart) SymbolAxis(org.jfree.chart.axis.SymbolAxis)

Example 2 with XYBlockRenderer

use of org.jfree.chart.renderer.xy.XYBlockRenderer in project spf4j by zolyfarkas.

the class Charts method createHeatJFreeChart.

@SuppressFBWarnings("CE_CLASS_ENVY")
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) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)2 XYPlot (org.jfree.chart.plot.XYPlot)2 XYBlockRenderer (org.jfree.chart.renderer.xy.XYBlockRenderer)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Color (java.awt.Color)1 ColorScale (org.cytoscape.ding.internal.charts.util.ColorScale)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 SymbolAxis (org.jfree.chart.axis.SymbolAxis)1 PlotOrientation (org.jfree.chart.plot.PlotOrientation)1 PaintScale (org.jfree.chart.renderer.PaintScale)1 PaintScaleLegend (org.jfree.chart.title.PaintScaleLegend)1 RectangleInsets (org.jfree.ui.RectangleInsets)1