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

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

Introduction

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

Prototype

public XYItemRenderer getRenderer() 

Source Link

Document

Returns the renderer for the primary dataset.

Usage

From source file:diplomawork.model.JPEGSaver.java

public void saveChartToFile(JFreeChart chart, boolean trainFlag) {
    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setVisible(false);
    plot.getRangeAxis().setVisible(false);
    plot.setBackgroundAlpha(0);/* w  w w  . j a  va2  s  .c om*/
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setOutlinePaint(null);
    XYItemRenderer r = plot.getRenderer();

    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setSeriesPaint(0, Color.BLACK);
    }
    plot.getRenderer().setSeriesStroke(0, new java.awt.BasicStroke(4f));
    File f = null;
    if (trainFlag) {
        nameOfJPGFile = "src/resorce/TranePlot" + trainCount++ + ".jpg";
        f = new File(nameOfJPGFile);
    } else {
        //            f = new File("src/resorce/Plot" + n++ + ".jpg");
        f = new File("src/resorce/Plot" + ".jpg");
    }

    try {
        ChartUtilities.saveChartAsJPEG(f, chart, 80, 80);
    } catch (IOException ex) {
        Logger.getLogger(JPEGSaver.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.knime.knip.core.ui.imgviewer.panels.HistogramBC.java

private final void setTheme(final JFreeChart chart) {
    final XYPlot plot = (XYPlot) chart.getPlot();
    final XYBarRenderer r = (XYBarRenderer) plot.getRenderer();
    final StandardXYBarPainter bp = new StandardXYBarPainter();
    r.setBarPainter(bp);// w  ww . j  a v a 2 s  . c o m
    // set Bar Color
    r.setSeriesPaint(0, Color.gray);
    r.setSeriesOutlinePaint(0, Color.gray);
    r.setShadowVisible(false);
    r.setDrawBarOutline(true);
    setBackgroundDefault(chart);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setTickLabelsVisible(false);
    rangeAxis.setTickMarksVisible(false);
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setTickLabelsVisible(false);
    domainAxis.setTickMarksVisible(false);
}

From source file:org.bench4Q.console.ui.section.LW_ConfigLoadShowSection.java

/**
 * @param args//from w  w  w.  j ava2  s  .  c o m
 * @return
 * @throws IOException
 */
public JPanel drawPreviewPic(Args args) throws IOException {

    XYSeriesCollection dataset = new XYSeriesCollection();

    ArrayList<TestPhase> ebs = args.getEbs();
    int prepairTime = args.getPrepair();
    int cooldownTime = args.getCooldown();

    ArrayList<XYSeries> series = new ArrayList<XYSeries>();
    int i = 1;
    for (TestPhase phase : ebs) {
        XYSeries seriesBasic = new XYSeries("Basic " + i);
        XYSeries seriesRandom = new XYSeries("Random " + i);
        series.add(seriesBasic);
        series.add(seriesRandom);
        int startTime = prepairTime + phase.getTriggerTime();
        int endTime = startTime + phase.getStdyTime();
        int startLoad = phase.getBaseLoad();
        int endLoad = startLoad + phase.getStdyTime() * phase.getRate();
        int startRadomLoad = startLoad + phase.getRandomLoad();
        int endRadomLoad = endLoad + phase.getRandomLoad();

        seriesBasic.add(new Double(startTime), new Integer(0));
        seriesBasic.add(new Double(startTime), new Integer(startLoad));
        seriesBasic.add(new Double(endTime), new Integer(endLoad));
        seriesBasic.add(new Double(endTime), new Integer(0));
        dataset.addSeries(seriesBasic);

        seriesRandom.add(new Double(startTime), new Integer(endLoad));
        seriesRandom.add(new Double(startTime), new Integer(startRadomLoad));
        seriesRandom.add(new Double(endTime), new Integer(endRadomLoad));
        seriesRandom.add(new Double(endTime), new Integer(0));
        dataset.addSeries(seriesRandom);

        i++;

    }

    final JFreeChart chart = ChartFactory.createXYStepAreaChart("Stacked Area Chart", // chart
            // title
            "time", // domain axis label
            "load", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);

    // color
    final XYPlot plot = chart.getXYPlot();

    int j = 0;
    for (XYSeries s : series) {

        if (j % 2 == 0) {
            plot.getRenderer().setSeriesPaint(j, Color.white);
        } else {
            plot.getRenderer().setSeriesPaint(j, Color.gray);
        }
        j++;
    }

    // fill shapes
    final XYStepAreaRenderer rend = (XYStepAreaRenderer) plot.getRenderer();
    rend.setShapesFilled(true);

    return new ChartPanel(chart);
}

From source file:net.sourceforge.processdash.ui.web.reports.snippets.EstErrorScatterChart.java

@Override
public JFreeChart createChart() {
    JFreeChart chart = super.createChart();

    // set minimum/maximum bounds on the two axes
    XYPlot xyPlot = chart.getXYPlot();
    double cutoff = getPercentParam("cut", 100, 200, 5000);
    xyPlot.setDomainAxis(truncAxis(xyPlot.getDomainAxis(), cutoff));
    xyPlot.setRangeAxis(truncAxis(xyPlot.getRangeAxis(), cutoff));
    xyPlot.setRenderer(new TruncatedItemRenderer(xyPlot.getRenderer()));

    // add a box illustrating the target range
    if (data.numRows() > 0) {
        double box = getPercentParam("pct", 0, 50, 100);
        xyPlot.addAnnotation(new XYBoxAnnotation(-box, -box, box, box));
        xyPlot.addAnnotation(new XYLineAnnotation(-box, 0, box, 0));
        xyPlot.addAnnotation(new XYLineAnnotation(0, -box, 0, box));
    }/* w w  w . j  a v  a 2 s  .  co  m*/

    return chart;
}

From source file:ch.zhaw.ias.dito.ui.AnalysisPanel.java

private JFreeChart createQuestionChart(String title, double[][] values) {
    JFreeChart chart = ChartFactory.createScatterPlot(title, null, null, new MdsXYDataset(values),
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(1, new VectorRenderer());
    plot.setDataset(1, getVectorDataset(values));
    plot.getRenderer().setBaseItemLabelsVisible(true);

    plot.getRenderer().setBaseItemLabelPaint(Color.BLUE);
    plot.getRenderer().setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        @Override//from w w  w .j ava 2  s. com
        public String generateLabel(XYDataset dataset, int series, int item) {
            //return "#" + (item + 1);
            return "#" + (item + 1) + ":" + Config.INSTANCE.getDitoConfig().getQuestion(item + 1).getName();
        }
    });
    plot.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            return "#" + (item + 1) + ":" + Config.INSTANCE.getDitoConfig().getQuestion(item + 1).getName();
        }
    });
    return chart;
}

From source file:com.itemanalysis.jmetrik.swing.GraphPanel.java

/**
 * This method should be called after a chart dataset is updated. It
 * will iterate over all XYDatasets and provide the line color and lineStyle.
 * If it is called before a chart has a dataset, it will not have an effect.
 *
 * @param plot/*from w  w w .j  ava  2 s.  co  m*/
 */
public void setXYPlotRenderer(XYPlot plot) {
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    int n = plot.getSeriesCount();

    for (int i = 0; i < n; i++) {
        Stroke stroke = new BasicStroke(lineWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f,
                getLineStyle(i), 0.0f);
        renderer.setSeriesStroke(i, stroke);
        renderer.setSeriesPaint(i, getPaintColor(i));
    }
    renderer.setLegendLine(new Line2D.Double(0, 5, 40, 5));
    renderer.setBaseShapesFilled(false);
    renderer.setBaseShapesVisible(showMarkers);
    renderer.setDrawSeriesLineAsPath(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRenderer(renderer);
}

From source file:Presentation.MainWindow.java

/** Ajout  la fentre des graphiques de temprature et d'humidit en temps rel */
public void initGraphs() {
    XYSeriesCollection datasetT = new XYSeriesCollection();
    XYSeriesCollection datasetH = new XYSeriesCollection();

    datasetT.addSeries(seriesT);/*from www .  j  av  a2  s  .  c  o m*/
    datasetH.addSeries(seriesH);

    XYPlot plotT = new XYPlot(datasetT, new NumberAxis(), new NumberAxis(), new DefaultXYItemRenderer());
    XYPlot plotH = new XYPlot(datasetH, new NumberAxis(), new NumberAxis(), new DefaultXYItemRenderer());

    //plot.setDataset(1, datasetT);
    // plot.setRenderer(1, new DefaultXYItemRenderer());
    plotH.getRenderer().setSeriesPaint(0, Color.BLUE);
    JFreeChart chartT = new JFreeChart("Graphique de temprature", JFreeChart.DEFAULT_TITLE_FONT, plotT, true);
    JFreeChart chartH = new JFreeChart("Graphique d'humidit", JFreeChart.DEFAULT_TITLE_FONT, plotH, true);

    ChartPanel gPanelT = new ChartPanel(chartT);
    ChartPanel gPanelH = new ChartPanel(chartH);

    mPanel.add(gPanelT);
    mPanel.add(gPanelH);
}

From source file:org.jfree.chart.demo.TimeSeriesDemo3.java

/**
 * Creates a new chart./*  ww w.  j av a2s.co m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The dataset.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series Demo 3", "Time", "Value", dataset,
            true, true, false);
    final XYPlot plot = chart.getXYPlot();
    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("MMM-yyyy")));
    axis.setVerticalTickLabels(true);

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPlotShapes(true);
    renderer.setSeriesShapesFilled(0, Boolean.TRUE);
    renderer.setSeriesShapesFilled(1, Boolean.FALSE);

    return chart;
}

From source file:net.bioclipse.model.ScatterPlotMouseHandler.java

public void mouseClicked(MouseEvent me) {
    Point2D p = null;//from ww w .j a va 2 s . c  o m
    ChartDescriptor cd = null;
    int[] indices = null;
    JFreeChart selectedChart = null;

    ChartPanel chartPanel = getChartPanel(me);
    p = chartPanel.translateScreenToJava2D(new Point(me.getX(), me.getY()));
    selectedChart = chartPanel.getChart();

    cd = ChartUtils.getChartDescriptor(selectedChart);
    indices = cd.getSourceIndices();

    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();

    XYItemRenderer plotRenderer = plot.getRenderer();

    if (!(plotRenderer instanceof ScatterPlotRenderer)) {
        throw new IllegalStateException(
                "Charts using ScatterPlotMouseHandler must use ScatterPlotRenderer as their renderer");
    }
    renderer = (ScatterPlotRenderer) plot.getRenderer();

    // now convert the Java2D coordinate to axis coordinates...
    Number xx = getDomainX(chartPanel, plot, p);
    Number yy = getRangeY(chartPanel, plot, p);

    //Find the selected point in the dataset
    //If shift is down, save old selections
    if (!me.isShiftDown() || currentSelection == null) {
        currentSelection = new ChartSelection();
    }

    for (int j = 0; j < plot.getDataset().getItemCount(plot.getDataset().getSeriesCount() - 1); j++) {
        for (int i = 0; i < plot.getDataset().getSeriesCount(); i++) {
            Number xK = plot.getDataset().getX(i, j);
            Number yK = plot.getDataset().getY(i, j);
            Number xKCheck = xK.doubleValue() - xx.doubleValue();
            Number yKCheck = yK.doubleValue() - yy.doubleValue();
            Number xxCheck = xKCheck.doubleValue() * xKCheck.doubleValue();
            Number yyCheck = yKCheck.doubleValue() * yKCheck.doubleValue();
            //Check distance from click and point, don't want to mark points that are too far from the click
            if (Math.sqrt(xxCheck.doubleValue()) <= 0.1 && Math.sqrt(yyCheck.doubleValue()) <= 0.1) {
                //Create a new selection
                PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel());
                cp.setDataPoint(j, i);
                currentSelection.addPoint(cp);
                if (!me.isShiftDown())
                    renderer.clearMarkedPoints();
                renderer.addMarkedPoint(j, i);
                selectedChart.plotChanged(new PlotChangeEvent(plot));

            }
        }
    }
    currentSelection.setDescriptor(cd);
    ChartUtils.updateSelection(currentSelection);
}

From source file:fr.amap.commons.javafx.chart.ChartViewer.java

public static JFreeChart createBasicChart(String title, XYSeriesCollection dataset, String xAxisLabel,
        String yAxisLabel) {//from w w w.  j a  va  2  s.c  o m

    JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, true, false);

    String fontName = "Palatino";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    XYPlot plot = (XYPlot) chart.getPlot();

    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);

    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));

    chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    chart.getLegend().setFrame(BlockBorder.NONE);

    LegendTitle subtitle = (LegendTitle) chart.getSubtitles().get(0);
    subtitle.setHorizontalAlignment(HorizontalAlignment.LEFT);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);

        Ellipse2D.Float shape = new Ellipse2D.Float(-2.5f, -2.5f, 5.0f, 5.0f);
        renderer.setSeriesShape(0, shape);
    }

    return chart;
}