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

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

Introduction

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

Prototype

public XYPlot() 

Source Link

Document

Creates a new XYPlot instance with no dataset, no axes and no renderer.

Usage

From source file:ec.ui.chart.ChartPopup.java

private JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    JFreeChart result = new JFreeChart("", TsCharts.CHART_TITLE_FONT, plot, false);
    return result;
}

From source file:GeMSE.Visualization.ElbowPlot.java

public void Plot(ArrayList<Double[]> pvData, ArrayList<Double[]> dData, int cut) {
    double maxY = 0;

    float[] secYColor = new float[3];
    Color.RGBtoHSB(153, 245, 255, secYColor);

    float[] priYColor = new float[3];
    Color.RGBtoHSB(255, 255, 255, priYColor);

    float[] cutColor = new float[3];
    Color.RGBtoHSB(255, 255, 0, cutColor);

    //create the series - add some dummy data
    XYSeries pvSeries = new XYSeries("Percentage of variance        ");
    for (int i = 1; i < pvData.size(); i++) {
        pvSeries.add(pvData.get(i)[0], pvData.get(i)[1]);
        maxY = Math.max(maxY, pvData.get(i)[1]);
    }/*from www.j av a  2  s .  c  o  m*/

    XYSeries dSeries = new XYSeries("Percentage of differences between slopes        ");
    for (int i = 0; i < dData.size(); i++)
        dSeries.add(dData.get(i)[0], dData.get(i)[1]);

    XYSeries cutSeries = new XYSeries("Cut        ");
    cutSeries.add(cut, 0.0);
    cutSeries.add(cut, maxY);

    //create the datasets
    XYSeriesCollection pvDataSeries = new XYSeriesCollection();
    pvDataSeries.addSeries(pvSeries);

    XYSeriesCollection cutDataSeries = new XYSeriesCollection();
    cutDataSeries.addSeries(cutSeries);

    XYSeriesCollection dDataSeries = new XYSeriesCollection();
    dDataSeries.addSeries(dSeries);

    //construct the plot
    XYPlot plot = new XYPlot();
    plot.setDataset(0, pvDataSeries);
    plot.setDataset(1, cutDataSeries);
    plot.setDataset(2, dDataSeries);

    // use XYSplineRenderer if you want to smooth the lines.
    XYLineAndShapeRenderer pvRenderer = new XYLineAndShapeRenderer();
    pvRenderer.setSeriesPaint(0, Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));

    BasicStroke dstroke = new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 1.0f, 10.0f }, 0.0f);
    XYLineAndShapeRenderer dRenderer = new XYLineAndShapeRenderer();
    dRenderer.setSeriesPaint(0, Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    dRenderer.setSeriesStroke(0, dstroke);

    BasicStroke cutStoke = new BasicStroke(4);
    // use XYSplineRenderer if you want to smooth the lines.
    //XYSplineRenderer cutRenderer = new XYSplineRenderer();
    XYLineAndShapeRenderer cutRenderer = new XYLineAndShapeRenderer();
    cutRenderer.setSeriesPaint(0, Color.getHSBColor(cutColor[0], cutColor[1], cutColor[2]));
    cutRenderer.setSeriesStroke(0, cutStoke);

    plot.setRenderer(0, pvRenderer);
    plot.setRenderer(1, cutRenderer);
    plot.setRenderer(2, dRenderer);

    plot.setRangeAxis(0, new NumberAxis("\n\nPercentage of Variance"));
    plot.setRangeAxis(1, new NumberAxis("Percentage of Difference Between Slopes"));
    plot.setDomainAxis(new NumberAxis("Number of Clusters\n\n"));

    //Map the data to the appropriate axis
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToRangeAxis(1, 0);
    plot.mapDatasetToRangeAxis(2, 1);

    float[] hsbValues = new float[3];
    Color.RGBtoHSB(16, 23, 67, hsbValues);
    plot.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2]));

    Font axisLabelFont = new Font("Dialog", Font.PLAIN, 14);
    Font axisTickLabelFont = new Font("Dialog", Font.PLAIN, 12);
    Font legendFont = new Font("Dialog", Font.PLAIN, 14);

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

    plot.getDomainAxis().setTickLabelPaint(Color.white);
    plot.getDomainAxis().setLabelPaint(Color.white);
    plot.getDomainAxis().setLabelFont(axisLabelFont);
    plot.getDomainAxis().setTickLabelFont(axisTickLabelFont);

    plot.getRangeAxis().setTickLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));
    plot.getRangeAxis().setLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));
    plot.getRangeAxis().setLabelFont(axisLabelFont);
    plot.getRangeAxis().setTickLabelFont(axisTickLabelFont);

    plot.getRangeAxis(1).setTickLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    plot.getRangeAxis(1).setLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    plot.getRangeAxis(1).setLabelFont(axisLabelFont);
    plot.getRangeAxis(1).setTickLabelFont(axisTickLabelFont);

    //generate the chart
    JFreeChart chart = new JFreeChart("\nSuggested number of clusters determined using Elbow method", getFont(),
            plot, true);

    chart.getTitle().setPaint(Color.white);
    chart.getLegend().setBackgroundPaint(Color.black);
    chart.getLegend().setItemPaint(Color.white);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);
    chart.getLegend().setItemFont(legendFont);

    float[] hsbValues2 = new float[3];
    Color.RGBtoHSB(36, 43, 87, hsbValues2);
    chart.setBackgroundPaint(Color.getHSBColor(hsbValues2[0], hsbValues2[1], hsbValues2[2]));
    JPanel chartPanel = new ChartPanel(chart);

    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    chartPanel.setPreferredSize(
            new java.awt.Dimension((int) Math.round((gd.getDisplayMode().getWidth() * 1.5) / 3.0),
                    (int) Math.round((gd.getDisplayMode().getHeight() * 1.5) / 3.0)));

    setContentPane(chartPanel);
}

From source file:daylightchart.daylightchart.chart.DaylightChart.java

/**
 * Instantiate the chart for a given location, and given year.
 *
 * @param riseSetData//from  w ww .j  av a  2  s  . co  m
 *        Rise and set data for the year
 * @param options
 *        Options
 */
public DaylightChart(final RiseSetYearData riseSetData, final Options options) {
    super(new XYPlot());
    this.riseSetData = riseSetData;
    createChart(options);
}

From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java

private static JFreeChart createTsChart() {
    XYPlot plot = new XYPlot();

    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickLabelsVisible(false);
    domainAxis.setLowerMargin(0.02);/*w w  w .ja va2s  .c  o m*/
    domainAxis.setUpperMargin(0.02);
    plot.setDomainAxis(domainAxis);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelsVisible(false);
    rangeAxis.setLowerMargin(0.02);
    rangeAxis.setUpperMargin(0.02);
    plot.setRangeAxis(rangeAxis);

    JFreeChart result = new JFreeChart("", null, plot, true);
    result.setPadding(new RectangleInsets(5, 5, 5, 5));
    result.getLegend().setFrame(BlockBorder.NONE);
    result.getLegend().setBackgroundPaint(null);

    return result;
}

From source file:net.sf.maltcms.chromaui.foldChangeViewer.ui.panel.FoldChangeViewPanel.java

/**
 * Creates new form Chromatogram1DViewPanel
 *///from  w ww .  j  a  v a2  s .  co m
public FoldChangeViewPanel(InstanceContent topComponentInstanceContent, Lookup tcLookup,
        ADataset1D<StatisticsContainer, FoldChangeElement> ds) {
    initComponents();
    this.content = topComponentInstanceContent;
    this.lookup = tcLookup;
    chart = new JFreeChart(new XYPlot());
    chartPanel = new ContextAwareChartPanel(chart, true, true, true, true, true);
    Cursor crosshairCursor = new Cursor(Cursor.CROSSHAIR_CURSOR);
    chartPanel.setCursor(crosshairCursor);
    chartPanel.setInitialDelay(100);
    chartPanel.setDismissDelay(30000);
    chartPanel.setReshowDelay(0);
    chartPanel.setFocusable(true);
    chartPanel.setMouseWheelEnabled(true);
    add(chartPanel, BorderLayout.CENTER);
    content.add(chartPanel);
}

From source file:de.bund.bfr.knime.nls.chart.ChartCreator.java

public ChartCreator(Map<String, Plotable> plotables, Map<String, String> legend) {
    this.plotables = plotables;
    this.legend = legend;
    colors = new LinkedHashMap<>();
    shapes = new LinkedHashMap<>();

    chartPanel = new ChartPanel(new JFreeChart(new XYPlot())) {

        private static final long serialVersionUID = 1L;

        @Override/*from   ww w .j a  v a  2s .c o  m*/
        public void mouseReleased(MouseEvent e) {
            ValueAxis domainAxis = ((XYPlot) chartPanel.getChart().getPlot()).getDomainAxis();
            ValueAxis rangeAxis = ((XYPlot) chartPanel.getChart().getPlot()).getRangeAxis();

            Range xRange1 = domainAxis.getRange();
            Range yRange1 = rangeAxis.getRange();
            super.mouseReleased(e);
            Range xRange2 = domainAxis.getRange();
            Range yRange2 = rangeAxis.getRange();

            if (!xRange1.equals(xRange2) || !yRange1.equals(yRange2)) {
                minX = xRange2.getLowerBound();
                maxX = xRange2.getUpperBound();
                minY = yRange2.getLowerBound();
                maxY = yRange2.getUpperBound();
                fireZoomChanged();
            }
        }
    };
    chartPanel.getPopupMenu().removeAll();

    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);
}

From source file:inflor.core.plots.DensityPlot.java

@Override
public JFreeChart createChart(FCSFrame data, TransformSet transforms) {
    Optional<FCSDimension> domainDimension = FCSUtilities.findCompatibleDimension(data,
            spec.getDomainAxisName());/*w w w .j av  a  2 s.  c  om*/
    Optional<FCSDimension> rangeDimension = FCSUtilities.findCompatibleDimension(data, spec.getRangeAxisName());
    if (domainDimension.isPresent() && rangeDimension.isPresent()) {
        AbstractTransform domainTransform = transforms.get(domainDimension.get().getShortName());
        double[] domainData = domainTransform.transform(domainDimension.get().getData());
        double domainMin = domainTransform.getMinTranformedValue();
        double domainMax = domainTransform.getMaxTransformedValue();

        AbstractTransform rangeTransform = transforms.get(rangeDimension.get().getShortName());
        double[] rangeData = rangeTransform.transform(rangeDimension.get().getData());
        double rangeMin = rangeTransform.getMinTranformedValue();
        double rangeMax = rangeTransform.getMaxTransformedValue();
        histogram = new Histogram2D(domainData, domainMin, domainMax, rangeData, rangeMin, rangeMax);

        DefaultXYZDataset plotData = new DefaultXYZDataset();

        BitSet nonEmptyMask = histogram.getNonEmptyBins();
        double[] x = FCSUtilities.filterColumn(nonEmptyMask, histogram.getXBins());
        double[] y = FCSUtilities.filterColumn(nonEmptyMask, histogram.getYBins());
        double[] z = FCSUtilities.filterColumn(nonEmptyMask, histogram.getZValues());
        plotData.addSeries(data.toString(), new double[][] { x, y, z });

        XYBlockRenderer renderer = updateRenderer(histogram);

        plot = new XYPlot();
        // Create the plot
        plot.setDataset(plotData);
        plot.setDomainAxis(PlotUtils.createAxis(domainDimension.get().getDisplayName(), domainTransform));
        plot.setRangeAxis(PlotUtils.createAxis(rangeDimension.get().getDisplayName(), rangeTransform));
        plot.setRenderer(renderer);
        // Add to panel.
        JFreeChart chart = new JFreeChart(plot);
        chart.removeLegend();
        return chart;
    } else {
        return null;
    }
}

From source file:playground.dgrether.analysis.charts.DgAvgDeltaUtilsModeGroupChart.java

@Override
public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Income [Chf / Year]");
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    plot.setDomainAxis(xAxis);//w  w  w  .j a v a2  s. com
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    plot.setDataset(0, this.dataset);
    for (int i = 0; i <= 3; i++) {
        renderer2.setSeriesStroke(i, new BasicStroke(2.0f));
        renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f));
        renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a"));
    }
    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    return chart;
}

From source file:de.bund.bfr.knime.pmmlite.views.chart.ChartCreator.java

public ChartCreator(Map<String, Plotable> plotables, Map<String, String> legend) {
    this.plotables = plotables;
    this.legend = legend;
    colors = new LinkedHashMap<>();
    shapes = new LinkedHashMap<>();
    colorLists = new LinkedHashMap<>();
    shapeLists = new LinkedHashMap<>();

    chartPanel = new ChartPanel(new JFreeChart(new XYPlot())) {

        private static final long serialVersionUID = 1L;

        @Override//from   w ww. ja va2 s  . c  o  m
        public void mouseReleased(MouseEvent e) {
            ValueAxis domainAxis = ((XYPlot) getChart().getPlot()).getDomainAxis();
            ValueAxis rangeAxis = ((XYPlot) getChart().getPlot()).getRangeAxis();

            Range xRange1 = domainAxis.getRange();
            Range yRange1 = rangeAxis.getRange();
            super.mouseReleased(e);
            Range xRange2 = domainAxis.getRange();
            Range yRange2 = rangeAxis.getRange();

            if (!xRange1.equals(xRange2) || !yRange1.equals(yRange2)) {
                minX = xRange2.getLowerBound();
                maxX = xRange2.getUpperBound();
                minY = yRange2.getLowerBound();
                maxY = yRange2.getUpperBound();
                fireZoomChanged();
            }
        }
    };
    chartPanel.getPopupMenu().removeAll();

    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);
}

From source file:org.vast.stt.renderer.JFreeChart.XYPlotBuilder.java

public void createPlot(ChartScene scene) {
    this.scene = scene; //  scene contains the axis info, so passing it in here for now

    datasetCount = 0;//from   ww  w. j  a  v  a  2s  .co  m
    rangeAxisCount = 0;
    currentItem = null;
    axisTable.clear();
    plot = new XYPlot();

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    String axisName = "Time (s)";
    NumberAxis domainAxis = new NumberAxis(axisName);
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setAutoRange(false);
    domainAxis.setNumberFormatOverride(new DateFormat());
    domainAxis.setTickLabelInsets(new RectangleInsets(0, 30, 0, 30));
    domainAxis.setLowerBound(scene.getDomainMin());
    domainAxis.setUpperBound(scene.getDomainMax());
    plot.setDomainAxis(datasetCount, domainAxis);
}