Example usage for org.jfree.chart.plot XYPlot setRangeGridlinePaint

List of usage examples for org.jfree.chart.plot XYPlot setRangeGridlinePaint

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setRangeGridlinePaint.

Prototype

public void setRangeGridlinePaint(Paint paint) 

Source Link

Document

Sets the paint for the grid lines plotted against the range axis and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:com.rapidminer.gui.plotter.charts.DistributionPlotter.java

@Override
public void updatePlotter() {

    JFreeChart chart = null;/*from   w w  w .  java 2s .co m*/
    Attribute attr = null;
    if (plotColumn != -1 && createFromModel) {
        attr = model.getTrainingHeader().getAttributes().get(model.getAttributeNames()[plotColumn]);
    }
    if (attr != null && attr.isNominal()
            && attr.getMapping().getValues().size() > MAX_NUMBER_OF_DIFFERENT_NOMINAL_VALUES) {
        // showing no chart because of too many different values
        chart = new JFreeChart(new Plot() {

            private static final long serialVersionUID = 1L;

            @Override
            public String getPlotType() {
                return "empty";
            }

            @Override
            public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
                    PlotRenderingInfo info) {
                String msg = I18N.getGUILabel("plotter_panel.too_many_nominals", "Distribution Plotter",
                        DistributionPlotter.MAX_NUMBER_OF_DIFFERENT_NOMINAL_VALUES);
                g2.setColor(Color.BLACK);
                g2.setFont(g2.getFont().deriveFont(g2.getFont().getSize() * 1.35f));
                g2.drawChars(msg.toCharArray(), 0, msg.length(), 50, (int) (area.getHeight() / 2 + 0.5d));
            }
        });
        AbstractChartPanel panel = getPlotterPanel();
        // Chart Panel Settings
        if (panel == null) {
            panel = createPanel(chart);
        } else {
            panel.setChart(chart);
        }
        // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
        panel.getChartRenderingInfo().setEntityCollection(null);
    } else {
        preparePlots();

        if (!createFromModel && (groupColumn < 0 || plotColumn < 0)) {
            CategoryDataset dataset = new DefaultCategoryDataset();
            chart = ChartFactory.createBarChart(null, // chart title
                    "Not defined", // x axis label
                    RANGE_AXIS_NAME, // y axis label
                    dataset, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, // tooltips
                    false // urls
            );
        } else {
            try {
                if (model.isDiscrete(translateToModelColumn(plotColumn))) {
                    chart = createNominalChart();
                } else {
                    chart = createNumericalChart();
                }
            } catch (Exception e) {
                // do nothing - just do not draw the chart
            }
        }

        if (chart != null) {
            chart.setBackgroundPaint(Color.white);

            // get a reference to the plot for further customization...
            Plot commonPlot = chart.getPlot();
            commonPlot.setBackgroundPaint(Color.WHITE);
            if (commonPlot instanceof XYPlot) {
                XYPlot plot = (XYPlot) commonPlot;

                plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
                plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

                // domain axis
                if (dataTable != null) {
                    if (dataTable.isDate(plotColumn) || dataTable.isDateTime(plotColumn)) {
                        DateAxis domainAxis = new DateAxis(dataTable.getColumnName(plotColumn));
                        domainAxis.setTimeZone(com.rapidminer.tools.Tools.getPreferredTimeZone());
                        plot.setDomainAxis(domainAxis);
                    } else {
                        NumberAxis numberAxis = new NumberAxis(dataTable.getColumnName(plotColumn));
                        plot.setDomainAxis(numberAxis);
                    }
                }

                plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD);
                plot.getDomainAxis().setTickLabelFont(LABEL_FONT);

                plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD);
                plot.getRangeAxis().setTickLabelFont(LABEL_FONT);

                // ranging
                if (dataTable != null) {
                    Range range = getRangeForDimension(plotColumn);
                    if (range != null) {
                        plot.getDomainAxis().setRange(range, true, false);
                    }

                    range = getRangeForName(RANGE_AXIS_NAME);
                    if (range != null) {
                        plot.getRangeAxis().setRange(range, true, false);
                    }
                }

                // rotate labels
                if (isLabelRotating()) {
                    plot.getDomainAxis().setTickLabelsVisible(true);
                    plot.getDomainAxis().setVerticalTickLabels(true);
                }

            } else if (commonPlot instanceof CategoryPlot) {
                CategoryPlot plot = (CategoryPlot) commonPlot;

                plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
                plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

                plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD);
                plot.getRangeAxis().setTickLabelFont(LABEL_FONT);

                plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD);
                plot.getDomainAxis().setTickLabelFont(LABEL_FONT);
            }

            // legend settings
            LegendTitle legend = chart.getLegend();
            if (legend != null) {
                legend.setPosition(RectangleEdge.TOP);
                legend.setFrame(BlockBorder.NONE);
                legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
                legend.setItemFont(LABEL_FONT);
            }

            AbstractChartPanel panel = getPlotterPanel();
            // Chart Panel Settings
            if (panel == null) {
                panel = createPanel(chart);
            } else {
                panel.setChart(chart);
            }

            // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
            panel.getChartRenderingInfo().setEntityCollection(null);
        }
    }
}

From source file:ecg.ecgshow.ECGShowUI.java

private void createECGData(long timeZone) {
    ECGData = new JPanel(new GridLayout(LEAD_COUNT, 1));
    dateAxises = new DateAxis[LEAD_COUNT];
    ECGSeries = new TimeSeries[LEAD_COUNT * 2];
    for (int i = 0; i < LEAD_COUNT; i++) {
        TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); //XYDataset  TimeSeriesCollection
        ECGSeries[i] = new TimeSeries("?" + (i + 1));
        ECGSeries[i].setMaximumItemCount(500);
        ECGSeries[i + LEAD_COUNT] = new TimeSeries("");
        ECGSeries[i + LEAD_COUNT].setMaximumItemAge(timeZone);
        ECGSeries[i + LEAD_COUNT].setMaximumItemCount(2);

        timeseriescollection.addSeries(ECGSeries[i]);
        timeseriescollection.addSeries(ECGSeries[i + LEAD_COUNT]);

        //DateAxis dateaxis = new DateAxis("Time");
        dateAxises[i] = new DateAxis("");
        dateAxises[i].setTickLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.016)));
        dateAxises[i].setLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.018)));
        dateAxises[i].setTickLabelsVisible(true);
        dateAxises[i].setVisible(false);

        //NumberAxis numberaxis = new NumberAxis("ecg");
        NumberAxis numberaxis = new NumberAxis("ecg");
        numberaxis.setTickLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.016)));
        numberaxis.setLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.018)));
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        numberaxis.setVisible(false);//from   w  ww  .ja  v a2s  .  c o m
        numberaxis.setLowerBound(1500D);
        numberaxis.setUpperBound(3000D);

        XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
        xylineandshaperenderer.setSeriesPaint(0, Color.GREEN); //
        xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(2));
        xylineandshaperenderer.setSeriesPaint(1, Color.LIGHT_GRAY); //
        xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(5));

        XYPlot xyplot = new XYPlot(timeseriescollection, dateAxises[i], numberaxis, xylineandshaperenderer);
        xyplot.setBackgroundPaint(Color.LIGHT_GRAY);
        xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
        xyplot.setBackgroundPaint(Color.BLACK);

        JFreeChart jfreechart = new JFreeChart(xyplot);
        jfreechart.setBackgroundPaint(new Color(237, 237, 237));//?
        jfreechart.getLegend().setVisible(false);

        ChartPanel chartpanel = new ChartPanel(jfreechart, (int) (WIDTH * 46 / 100), (int) (HEIGHT * 17 / 100),
                0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, true, true, false, true, false, false);

        chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0) //??0
                , BorderFactory.createEmptyBorder() //????
        ));
        chartpanel.setMouseZoomable(false); //?
        ECGData.add(chartpanel);
    }
}

From source file:ecg.ecgshow.ECGShowUI.java

private void createPressureData(long timeZone) {
    PressureData = new JPanel();
    PressuredateAxises = new DateAxis[1];
    SystolicPressureSeries = new TimeSeries[2];
    DiastolicPressureSeries = new TimeSeries[2];

    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    SystolicPressureSeries[0] = new TimeSeries("");
    SystolicPressureSeries[0].setMaximumItemAge(timeZone);
    SystolicPressureSeries[0].setMaximumItemCount(500);
    SystolicPressureSeries[1] = new TimeSeries("");
    SystolicPressureSeries[1].setMaximumItemAge(timeZone);
    SystolicPressureSeries[1].setMaximumItemCount(2);
    timeseriescollection.addSeries(SystolicPressureSeries[0]);
    timeseriescollection.addSeries(SystolicPressureSeries[1]);

    PressuredateAxises[0] = new DateAxis("");
    PressuredateAxises[0].setTickLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.016)));
    PressuredateAxises[0].setLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.018)));
    PressuredateAxises[0].setTickLabelsVisible(true);
    PressuredateAxises[0].setVisible(false);

    DiastolicPressureSeries[0] = new TimeSeries("");
    DiastolicPressureSeries[0].setMaximumItemAge(timeZone);
    DiastolicPressureSeries[0].setMaximumItemCount(500);
    DiastolicPressureSeries[1] = new TimeSeries("");
    DiastolicPressureSeries[1].setMaximumItemAge(timeZone);
    DiastolicPressureSeries[1].setMaximumItemCount(2);
    timeseriescollection.addSeries(DiastolicPressureSeries[0]);
    timeseriescollection.addSeries(DiastolicPressureSeries[1]);

    NumberAxis numberaxis = new NumberAxis("Pressure");
    numberaxis.setTickLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.016)));
    numberaxis.setLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.018)));
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setVisible(false);//www  . j  a va 2s.  c  o  m
    numberaxis.setLowerBound(0D);
    numberaxis.setUpperBound(200D);

    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
    xylineandshaperenderer.setSeriesPaint(0, Color.GREEN); //
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(2)); //
    xylineandshaperenderer.setSeriesPaint(1, Color.LIGHT_GRAY); //
    xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(5));

    xylineandshaperenderer.setSeriesPaint(2, Color.ORANGE); //
    xylineandshaperenderer.setSeriesStroke(2, new BasicStroke(2)); //
    xylineandshaperenderer.setSeriesPaint(3, Color.LIGHT_GRAY); //
    xylineandshaperenderer.setSeriesStroke(3, new BasicStroke(5));

    //XYPlot xyplot = new XYPlot(timeseriescollection, PressuredateAxises[0], numberaxis, xylineandshaperenderer);
    XYPlot xyplot = new XYPlot(timeseriescollection, dateAxises[0], numberaxis, xylineandshaperenderer);

    xyplot.setBackgroundPaint(Color.LIGHT_GRAY);
    xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setBackgroundPaint(Color.BLACK);

    JFreeChart jfreechart = new JFreeChart(xyplot);
    jfreechart.setBackgroundPaint(new Color(237, 237, 237));//?
    jfreechart.getLegend().setVisible(false);

    ChartPanel chartpanel = new ChartPanel(jfreechart, (int) (WIDTH * 0.155), (int) (HEIGHT * 0.18), 0, 0,
            Integer.MAX_VALUE, Integer.MAX_VALUE, true, true, false, true, false, false);

    chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0) //??0
            , BorderFactory.createEmptyBorder() //????
    ));
    chartpanel.setMouseZoomable(false);
    PressureData.add(chartpanel);

}

From source file:gui.QTLResultsPanel.java

private JPanel getChart(Trait trait) {
    JFreeChart chart = ChartFactory.createXYLineChart(null, "Position (cM)", "LOD Score", null,
            PlotOrientation.VERTICAL, true, true, false);

    setChartData(chart, trait);/*from   w  ww. j a  v a  2 s .c  om*/

    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    chart.setRenderingHints(rh);
    chart.removeLegend();

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(new Color(255, 255, 220));
    plot.setDomainGridlinePaint(new Color(128, 128, 128));
    plot.setRangeGridlinePaint(new Color(128, 128, 128));

    ValueAxis axis = plot.getRangeAxis();
    if (trait.maxLOD <= 3) {
        axis.setUpperBound(3);
    }

    PermResult result = trait.getPermResult();
    if (result != null) {
        float[] dashPattern = { 5, 5 };
        BasicStroke s1 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, dashPattern, 0);

        ValueMarker m1 = new ValueMarker(result.getSig90(), new Color(0, 0, 60), s1, null, null, 1.0f);
        ValueMarker m2 = new ValueMarker(result.getSig95(), new Color(0, 0, 60), s1, null, null, 1.0f);

        plot.addRangeMarker(m1);
        plot.addRangeMarker(m2);

        if (result.getSig95() > trait.maxLOD && result.getSig95() >= 3) {
            axis.setUpperBound(result.getSig95() * (1.05));
        }
    }

    chartPanel = new ChartPanel(chart);
    chartPanel.setPopupMenu(null);
    return chartPanel;
}

From source file:com.charts.IntradayChart.java

public IntradayChart(YStockQuote currentStock) {

    TimeSeries series = new TimeSeries(currentStock.get_name());
    ArrayList<String> fiveDayData = currentStock.get_one_day_data();
    int length = fiveDayData.size();
    for (int i = 17; i < length; i++) {
        String[] data = fiveDayData.get(i).split(",");
        Date time = new Date((long) Integer.parseInt(data[0]) * 1000);
        DateFormat df = new SimpleDateFormat("MM-dd-yyyy-h-m");
        series.addOrUpdate(new Minute(time), Double.parseDouble(data[1]));
    }//from   w ww.  j a  v a2s. c o  m
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(
            currentStock.get_name() + "(" + currentStock.get_symbol() + ")" + " Intraday", "Date", "Price",
            dataset, true, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    ValueAxis yAxis = (ValueAxis) plot.getRangeAxis();
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();
    xAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
    xAxis.setDateFormatOverride(new SimpleDateFormat("h:m a"));
    xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    //xAxis.setVerticalTickLabels(true);
    chartPanel = new ChartPanel(chart);
    chart.setBackgroundPaint(chartPanel.getBackground());
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    chartPanel.setVisible(true);
    chartPanel.revalidate();
    chartPanel.repaint();
}

From source file:adams.flow.sink.JFreeChartPlot.java

/**
 * Creates a new display panel for the token.
 *
 * @param token   the token to display in a new panel, can be null
 * @return      the generated panel/*w w  w  .j  a  v a  2s. c o m*/
 */
@Override
public DisplayPanel createDisplayPanel(Token token) {
    AbstractDisplayPanel result;

    result = new AbstractComponentDisplayPanel(getClass().getSimpleName()) {
        private static final long serialVersionUID = -3785685146120118884L;
        protected JFreeChart m_JFreeChart;
        protected ChartPanel m_PlotPanel;

        @Override
        protected void initGUI() {
            super.initGUI();
            setLayout(new BorderLayout());
        }

        @Override
        public void display(Token token) {
            SpreadSheet sheet = (SpreadSheet) token.getPayload();
            Dataset dataset = m_Dataset.generate(sheet);
            m_JFreeChart = m_Chart.generate(dataset);
            if (m_JFreeChart.getPlot() instanceof XYPlot) {
                XYPlot plot = (XYPlot) m_JFreeChart.getPlot();
                plot.setDomainGridlinesVisible(true);
                plot.setDomainGridlinePaint(Color.GRAY);
                plot.setRangeGridlinesVisible(true);
                plot.setRangeGridlinePaint(Color.GRAY);
                plot.getRenderer().setSeriesPaint(0, m_PlotColor);
                if (plot.getSeriesCount() > 1)
                    plot.getRenderer().setSeriesPaint(1, m_DiagonalColor);
                Shape shape = m_Shape.generate();
                if (shape != null)
                    plot.getRenderer().setSeriesShape(0, shape);
            }
            m_PlotPanel = new ChartPanel(m_JFreeChart);
            removeAll();
            add(m_PlotPanel, BorderLayout.CENTER);
        }

        @Override
        public void clearPanel() {
            removeAll();
            m_JFreeChart = null;
        }

        @Override
        public void cleanUp() {
            removeAll();
            m_JFreeChart = null;
        }

        @Override
        public JComponent supplyComponent() {
            return m_PlotPanel;
        }
    };

    if (token != null)
        result.display(token);

    return result;
}

From source file:com.rapidminer.gui.plotter.charts.SeriesChartPlotter.java

private JFreeChart createChart(XYDataset dataset, boolean createLegend) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, createLegend, // include legend
            true, // tooltips
            false // urls
    );/*  www  . java2 s .  c  om*/

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    DeviationRenderer renderer = new DeviationRenderer(true, false);

    // colors
    if (dataset.getSeriesCount() == 1) {
        renderer.setSeriesStroke(0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        renderer.setSeriesPaint(0, getColorProvider().getPointColor(1.0d));
    } else { // special case needed for avoiding devision by zero
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            renderer.setSeriesStroke(i, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            renderer.setSeriesPaint(i,
                    getColorProvider().getPointColor(1.0d - i / (double) (dataset.getSeriesCount() - 1)));
        }
    }
    // background for bounds
    if (plotBounds) {
        float[] dashArray = new float[] { 7, 14 };
        renderer.setSeriesStroke(boundsSeriesIndex,
                new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, dashArray, 0));
        renderer.setSeriesPaint(boundsSeriesIndex, Color.GRAY.brighter());
        renderer.setSeriesFillPaint(boundsSeriesIndex, Color.GRAY);
    }
    // alpha
    renderer.setAlpha(0.25f);

    plot.setRenderer(renderer);

    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    if (axis[INDEX] < 0) {
        xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
        xAxis.setLabel(SERIESINDEX_LABEL);
        Range range = getRangeForName(SERIESINDEX_LABEL);
        if (range == null) {
            xAxis.setAutoRange(true);
            xAxis.setAutoRangeStickyZero(false);
            xAxis.setAutoRangeIncludesZero(false);
        } else {
            xAxis.setRange(range, true, false);
        }
    } else {
        xAxis.setLabel(dataTable.getColumnName(axis[INDEX]));
        Range range = getRangeForDimension(axis[INDEX]);
        if (range == null) {
            xAxis.setAutoRange(true);
            xAxis.setAutoRangeStickyZero(false);
            xAxis.setAutoRangeIncludesZero(false);
        } else {
            xAxis.setRange(range, true, false);
        }
    }

    xAxis.setLabelFont(LABEL_FONT_BOLD);
    xAxis.setTickLabelFont(LABEL_FONT);
    xAxis.setVerticalTickLabels(isLabelRotating());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLabel(VALUEAXIS_LABEL);
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));
    setYAxisRange(yAxis);

    yAxis.setLabelFont(LABEL_FONT_BOLD);
    yAxis.setTickLabelFont(LABEL_FONT);

    return chart;
}

From source file:org.eumetsat.metop.visat.SounderInfoView.java

protected void configureSpectrumPlot(XYPlot plot) {
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(false);
    plot.setNoDataMessage(NO_IFOV_SELECTED);
}

From source file:com.igalia.java.zk.components.JFreeChartEngine.java

public byte[] drawChart(Object data) {
    Chart chart = (Chart) data;//from   w  w  w.j  av a  2s.c o m
    ChartImpl impl = getChartImpl(chart);
    JFreeChart jfchart = impl.createChart(chart);

    Plot plot = (Plot) jfchart.getPlot();
    float alpha = (float) (((float) chart.getFgAlpha()) / 255);
    plot.setForegroundAlpha(alpha);

    alpha = (float) (((float) chart.getBgAlpha()) / 255);
    plot.setBackgroundAlpha(alpha);

    int[] bgRGB = chart.getBgRGB();
    if (bgRGB != null) {
        plot.setBackgroundPaint(new Color(bgRGB[0], bgRGB[1], bgRGB[2], chart.getBgAlpha()));
    }

    int[] paneRGB = chart.getPaneRGB();
    if (paneRGB != null) {
        jfchart.setBackgroundPaint(new Color(paneRGB[0], paneRGB[1], paneRGB[2], chart.getPaneAlpha()));
    }

    //since 3.6.3, JFreeChart 1.0.13 change default fonts which does not support Chinese, allow
    //developer to set font.

    //title font
    final Font tfont = chart.getTitleFont();
    if (tfont != null) {
        jfchart.getTitle().setFont(tfont);
    }

    //legend font
    final Font lfont = chart.getLegendFont();
    if (lfont != null) {
        jfchart.getLegend().setItemFont(lfont);
    }

    if (plot instanceof CategoryPlot) {
        final CategoryPlot cplot = (CategoryPlot) plot;
        cplot.setRangeGridlinePaint(new Color(0xc0, 0xc0, 0xc0));

        //Domain axis(x axis)
        final Font xlbfont = chart.getXAxisFont();
        final Font xtkfont = chart.getXAxisTickFont();
        if (xlbfont != null) {
            cplot.getDomainAxis().setLabelFont(xlbfont);
        }
        if (xtkfont != null) {
            cplot.getDomainAxis().setTickLabelFont(xtkfont);
        }

        Color[] colorMappings = (Color[]) chart.getAttribute("series-color-mappings");
        if (colorMappings != null) {
            for (int ii = 0; ii < colorMappings.length; ii++) {
                cplot.getRenderer().setSeriesPaint(ii, colorMappings[ii]);
            }
        }

        Double lowerBound = (Double) chart.getAttribute("range-axis-lower-bound");
        if (lowerBound != null) {
            cplot.getRangeAxis().setAutoRange(false);
            cplot.getRangeAxis().setLowerBound(lowerBound);
        }

        Double upperBound = (Double) chart.getAttribute("range-axis-upper-bound");
        if (upperBound != null) {
            cplot.getRangeAxis().setAutoRange(false);
            cplot.getRangeAxis().setUpperBound(upperBound);
        }

        //Range axis(y axis)
        final Font ylbfont = chart.getYAxisFont();
        final Font ytkfont = chart.getYAxisTickFont();
        if (ylbfont != null) {
            cplot.getRangeAxis().setLabelFont(ylbfont);
        }
        if (ytkfont != null) {
            cplot.getRangeAxis().setTickLabelFont(ytkfont);
        }
    } else if (plot instanceof XYPlot) {
        final XYPlot xyplot = (XYPlot) plot;
        xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);

        //Domain axis(x axis)
        final Font xlbfont = chart.getXAxisFont();
        final Font xtkfont = chart.getXAxisTickFont();
        if (xlbfont != null) {
            xyplot.getDomainAxis().setLabelFont(xlbfont);
        }
        if (xtkfont != null) {
            xyplot.getDomainAxis().setTickLabelFont(xtkfont);
        }

        //Range axis(y axis)
        final Font ylbfont = chart.getYAxisFont();
        final Font ytkfont = chart.getYAxisTickFont();
        if (ylbfont != null) {
            xyplot.getRangeAxis().setLabelFont(ylbfont);
        }
        if (ytkfont != null) {
            xyplot.getRangeAxis().setTickLabelFont(ytkfont);
        }
    } else if (plot instanceof PiePlot) {
        plot.setOutlineStroke(null);
    }

    //callbacks for each area
    ChartRenderingInfo jfinfo = new ChartRenderingInfo();
    BufferedImage bi = jfchart.createBufferedImage(chart.getIntWidth(), chart.getIntHeight(),
            Transparency.TRANSLUCENT, jfinfo);

    //remove old areas
    if (chart.getChildren().size() > 20)
        chart.invalidate(); //improve performance if too many chart
    chart.getChildren().clear();

    if (Events.isListened(chart, Events.ON_CLICK, false) || chart.isShowTooltiptext()) {
        int j = 0;
        String preUrl = null;
        for (Iterator it = jfinfo.getEntityCollection().iterator(); it.hasNext();) {
            ChartEntity ce = (ChartEntity) it.next();
            final String url = ce.getURLText();

            //workaround JFreeChart's bug (skip replicate areas)
            if (url != null) {
                if (preUrl == null) {
                    preUrl = url;
                } else if (url.equals(preUrl)) { //start replicate, skip
                    break;
                }
            }

            //1. JFreeChartEntity area cover the whole chart, will "mask" other areas
            //2. LegendTitle area cover the whole legend, will "mask" each legend
            //3. PlotEntity cover the whole chart plotting araa, will "mask" each bar/line/area
            if (!(ce instanceof JFreeChartEntity)
                    && !(ce instanceof TitleEntity && ((TitleEntity) ce).getTitle() instanceof LegendTitle)
                    && !(ce instanceof PlotEntity)) {
                Area area = new Area();
                area.setParent(chart);
                area.setCoords(ce.getShapeCoords());
                area.setShape(ce.getShapeType());
                area.setId("area_" + chart.getId() + '_' + (j++));
                if (chart.isShowTooltiptext() && ce.getToolTipText() != null) {
                    area.setTooltiptext(ce.getToolTipText());
                }
                area.setAttribute("url", ce.getURLText());
                impl.render(chart, area, ce);
                if (chart.getAreaListener() != null) {
                    try {
                        chart.getAreaListener().onRender(area, ce);
                    } catch (Exception ex) {
                        throw UiException.Aide.wrap(ex);
                    }
                }
            }
        }
    }
    //clean up the "LEGEND_SEQ"
    //used for workaround LegendItemEntity.getSeries() always return 0
    //used for workaround TickLabelEntity no information
    chart.removeAttribute("LEGEND_SEQ");
    chart.removeAttribute("TICK_SEQ");

    try {
        //encode into png image format byte array
        return EncoderUtil.encode(bi, ImageFormat.PNG, true);
    } catch (java.io.IOException ex) {
        throw UiException.Aide.wrap(ex);
    }
}

From source file:com.rapidminer.gui.plotter.charts.BubbleChartPlotter.java

@Override
public void updatePlotter() {
    final DataTable dataTable = getDataTable();

    prepareData();//  ww w  . j  a  v  a2 s.  co m

    JFreeChart chart = ChartFactory.createBubbleChart(null, // chart title
            null, // domain axis label
            null, // range axis label
            xyzDataSet, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // URLs
    );

    if (axis[X_AXIS] >= 0 && axis[Y_AXIS] >= 0 && axis[BUBBLE_SIZE_AXIS] >= 0) {
        if (nominal) {
            int size = xyzDataSet.getSeriesCount();
            chart = ChartFactory.createBubbleChart(null, // chart title
                    null, // domain axis label
                    null, // range axis label
                    xyzDataSet, // data
                    PlotOrientation.VERTICAL, // orientation
                    colorColumn >= 0 && size < 100 ? true : false, // include legend
                    true, // tooltips
                    false // URLs
            );

            // renderer settings
            XYBubbleRenderer renderer = (XYBubbleRenderer) chart.getXYPlot().getRenderer();
            renderer.setBaseOutlinePaint(Color.BLACK);

            if (size > 1) {
                for (int i = 0; i < size; i++) {
                    renderer.setSeriesPaint(i, getColorProvider(true).getPointColor(i / (double) (size - 1)));
                    renderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 7, 7));
                }
            } else {
                renderer.setSeriesPaint(0, getColorProvider().getPointColor(1.0d));
                renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 7, 7));
            }

            // legend settings
            LegendTitle legend = chart.getLegend();
            if (legend != null) {
                legend.setPosition(RectangleEdge.TOP);
                legend.setFrame(BlockBorder.NONE);
                legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
                legend.setItemFont(LABEL_FONT);
            }
        } else {
            chart = ChartFactory.createScatterPlot(null, // chart title
                    null, // domain axis label
                    null, // range axis label
                    xyzDataSet, // data
                    PlotOrientation.VERTICAL, // orientation
                    false, // include legend
                    true, // tooltips
                    false // URLs
            );

            // renderer settings
            ColorizedBubbleRenderer renderer = new ColorizedBubbleRenderer(this.colors);
            renderer.setBaseOutlinePaint(Color.BLACK);
            chart.getXYPlot().setRenderer(renderer);

            // legend settings
            chart.addLegend(new LegendTitle(renderer) {

                private static final long serialVersionUID = 1288380309936848376L;

                @Override
                public Object draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area,
                        java.lang.Object params) {
                    if (dataTable.isDate(colorColumn) || dataTable.isTime(colorColumn)
                            || dataTable.isDateTime(colorColumn)) {
                        drawSimpleDateLegend(g2, (int) (area.getCenterX() - 170), (int) (area.getCenterY() + 7),
                                dataTable, colorColumn, minColor, maxColor);
                        return new BlockResult();
                    } else {
                        final String minColorString = Tools.formatNumber(minColor);
                        final String maxColorString = Tools.formatNumber(maxColor);
                        drawSimpleNumericalLegend(g2, (int) (area.getCenterX() - 90),
                                (int) (area.getCenterY() + 7), dataTable.getColumnName(colorColumn),
                                minColorString, maxColorString);
                        return new BlockResult();
                    }
                }

                @Override
                public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area) {
                    draw(g2, area, null);
                }

            });
        }
    }

    // GENERAL CHART SETTINGS

    // set the background colors for the chart...
    chart.setBackgroundPaint(Color.WHITE);
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.getPlot().setForegroundAlpha(0.7f);

    XYPlot plot = chart.getXYPlot();
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis
    if (axis[X_AXIS] >= 0) {
        if (dataTable.isNominal(axis[X_AXIS])) {
            String[] values = new String[dataTable.getNumberOfValues(axis[X_AXIS])];
            for (int i = 0; i < values.length; i++) {
                values[i] = dataTable.mapIndex(axis[X_AXIS], i);
            }
            plot.setDomainAxis(new SymbolAxis(dataTable.getColumnName(axis[X_AXIS]), values));
        } else if (dataTable.isDate(axis[X_AXIS]) || dataTable.isDateTime(axis[X_AXIS])) {
            DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[X_AXIS]));
            domainAxis.setTimeZone(Tools.getPreferredTimeZone());
            plot.setDomainAxis(domainAxis);
        } else {
            if (logScales[X_AXIS]) {
                LogAxis domainAxis = new LogAxis(dataTable.getColumnName(axis[X_AXIS]));
                domainAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));
                plot.setDomainAxis(domainAxis);
            } else {
                plot.setDomainAxis(new NumberAxis(dataTable.getColumnName(axis[X_AXIS])));
            }
        }
        Range range = getRangeForDimension(axis[X_AXIS]);
        if (range != null) {
            plot.getDomainAxis().setRange(range, true, false);
        } else {
            plot.getDomainAxis().setAutoRange(true);
        }
    }
    plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getDomainAxis().setTickLabelFont(LABEL_FONT);

    // rotate labels
    if (isLabelRotating()) {
        plot.getDomainAxis().setTickLabelsVisible(true);
        plot.getDomainAxis().setVerticalTickLabels(true);
    }

    // range axis
    if (axis[Y_AXIS] >= 0) {
        if (dataTable.isNominal(axis[Y_AXIS])) {
            String[] values = new String[dataTable.getNumberOfValues(axis[Y_AXIS])];
            for (int i = 0; i < values.length; i++) {
                values[i] = dataTable.mapIndex(axis[Y_AXIS], i);
            }
            plot.setRangeAxis(new SymbolAxis(dataTable.getColumnName(axis[Y_AXIS]), values));
        } else if (dataTable.isDate(axis[Y_AXIS]) || dataTable.isDateTime(axis[Y_AXIS])) {
            DateAxis rangeAxis = new DateAxis(dataTable.getColumnName(axis[Y_AXIS]));
            rangeAxis.setTimeZone(Tools.getPreferredTimeZone());
            plot.setRangeAxis(rangeAxis);
        } else {
            plot.setRangeAxis(new NumberAxis(dataTable.getColumnName(axis[Y_AXIS])));
        }
        Range range = getRangeForDimension(axis[Y_AXIS]);
        if (range != null) {
            plot.getRangeAxis().setRange(range, true, false);
        } else {
            plot.getRangeAxis().setAutoRange(true);
        }
    }
    plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getRangeAxis().setTickLabelFont(LABEL_FONT);

    AbstractChartPanel panel = getPlotterPanel();
    // Chart Panel Settings
    if (panel == null) {
        panel = createPanel(chart);
    } else {
        panel.setChart(chart);
    }

    // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
    panel.getChartRenderingInfo().setEntityCollection(null);
}