Example usage for org.jfree.chart JFreeChart getXYPlot

List of usage examples for org.jfree.chart JFreeChart getXYPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getXYPlot.

Prototype

public XYPlot getXYPlot() 

Source Link

Document

Returns the plot cast as an XYPlot .

Usage

From source file:com.intel.stl.ui.configuration.view.SC2VLNTMTBarChartPanel.java

@Override
public void initComponents() {
    dataset = new XYSeriesCollection();

    JFreeChart chart = ComponentFactory.createXYBarChart(K1105_SC.getValue(), K1110_VLNT.getValue(), dataset,
            (XYItemLabelGenerator) null);

    XYPlot plot = chart.getXYPlot();
    plot.setDomainPannable(true);//ww  w.  j av  a  2s .  c om
    plot.setRangePannable(true);
    final String scLabel = "<html>" + K1105_SC.getValue() + ": ";
    final String vlntLabel = "<br>" + K1110_VLNT.getValue() + ": ";

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setBarAlignmentFactor(0);
    renderer.setMargin(0.2);

    renderer.setSeriesToolTipGenerator(0, new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int arg1, int arg2) {
            int scNum = (int) dataset.getXValue(arg1, arg2);
            int vlntCount = (int) dataset.getYValue(arg1, arg2);
            return scLabel + scNum + vlntLabel + vlntCount + "</html>";
        }
    });
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chartPanel = new ChartPanel(chart);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setPreferredSize(PREFERRED_CHART_SIZE);
    propsPanel.add(chartPanel);
}

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

/**
 * A demonstration application showing an XY plot, with a cyclic axis and renderer
 *
 * @param title  the frame title.// w w w. j ava 2 s  .  co m
 */
public CyclicXYPlotDemo(final String title) {

    super(title);

    this.series = new XYSeries("Random Data");
    this.series.setMaximumItemCount(50); // Only 50 items are visible at the same time. 
                                         // Keep more as a mean to test this.
    final XYSeriesCollection data = new XYSeriesCollection(this.series);

    final JFreeChart chart = ChartFactory.createXYLineChart("Cyclic XY Plot Demo", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

    final XYPlot plot = chart.getXYPlot();
    plot.setDomainAxis(new CyclicNumberAxis(10, 0));
    plot.setRenderer(new CyclicXYItemRenderer());

    final NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    axis.setAutoRangeMinimumSize(1.0);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(400, 300));
    final JPanel content = new JPanel(new BorderLayout());
    content.add(chartPanel, BorderLayout.CENTER);

    final JButton button1 = new JButton("Start");
    button1.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            timer.start();
        }
    });

    final JButton button2 = new JButton("Stop");
    button2.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            timer.stop();
        }
    });

    final JButton button3 = new JButton("Step by step");
    button3.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            CyclicXYPlotDemo.this.actionPerformed(null);
        }
    });

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(button1);
    buttonPanel.add(button2);
    buttonPanel.add(button3);

    content.add(buttonPanel, BorderLayout.SOUTH);
    setContentPane(content);

    this.timer = new Timer(200, this);
}

From source file:org.vimarsha.ui.TimeSlicedClassiferForm.java

private JFreeChart createChart(XYSeriesCollection dataSet, String chartTitle) {
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "Time slice number", "Classification",
            dataSet, PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();
    NumberAxis range = (NumberAxis) plot.getRangeAxis();

    range.setRange(0, 1.1);/* ww w  .j a  v  a2s  . c om*/
    TickUnits units = new TickUnits();
    units.add(new NumberTickUnit(0));
    units.add(new NumberTickUnit(0.5));
    units.add(new NumberTickUnit(1));

    range.setStandardTickUnits(units);
    range.setNumberFormatOverride(new DecimalFormat() {
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            if (number == 1)
                return toAppendTo.append("badfs");
            else if (number == 0.5)
                return toAppendTo.append("badma");
            else
                return toAppendTo.append("good");
        }
    });

    return chart;
}

From source file:com.kurvlrgui.gui.ChartPanel.java

/**
 * Creates new form ChartPanel//  w w w  . j  a v  a  2  s  .  co  m
 */
public ChartPanel(String title, NumericData s1, NumericData s2) {
    initComponents();

    calculated = new XYSeries("Calculated");
    for (NumericPair np : s1.values) {
        calculated.add(np.x, np.y);
    }

    observed = null;
    if (s2 != null) {
        observed = new XYSeries("Observed");
        for (NumericPair np : s2.values) {
            observed.add(np.x, np.y);
        }
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(calculated);
    if (s2 != null)
        dataset.addSeries(observed);

    JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", dataset, PlotOrientation.VERTICAL, true,
            true, false);
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();

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

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    panel = new org.jfree.chart.ChartPanel(chart);

    panel.setHorizontalAxisTrace(true);
    panel.setVerticalAxisTrace(true);

    this.add(panel);
}

From source file:financepro.XYLineChartExample.java

License:asdf

private JPanel createChartPanel() {
    // creates a line chart object
    // returns the chart panel
    String chartTitle = "Various Financial Ratios";
    String xAxisLabel = "Years";
    String yAxisLabel = "Ratio Values";

    XYDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset);

    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);/*from   w  w  w.j  a  v  a 2s  . c  o m*/

    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.YELLOW);
    renderer.setSeriesPaint(3, Color.CYAN);
    renderer.setSeriesPaint(4, Color.BLACK);

    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    renderer.setSeriesStroke(1, new BasicStroke(4.0f));
    renderer.setSeriesStroke(2, new BasicStroke(4.0f));
    renderer.setSeriesStroke(3, new BasicStroke(4.0f));
    renderer.setSeriesStroke(4, new BasicStroke(4.0f));

    plot.setRenderer(renderer);
    plot.setOutlinePaint(Color.BLUE);
    plot.setOutlineStroke(new BasicStroke(4.0f));
    plot.setBackgroundPaint(Color.DARK_GRAY);

    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.BLACK);

    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.BLACK);

    return new ChartPanel(chart);
}

From source file:net.sf.clichart.chart.AbstractChartBuilder.java

/**
 * Add the data set as the second axis to this chart
 *//*from   w  w  w.  jav  a  2 s.c  o m*/
public void addSecondAxis(JFreeChart chart, Options options) {
    XYPlot plot = chart.getXYPlot();
    plot.setDataset(1, getDataset());
    plot.mapDatasetToRangeAxis(1, 1);

    NumberAxis rangeAxis2 = new NumberAxis(options.getSecondAxisChartYAxisTitle());
    plot.setRangeAxis(1, rangeAxis2);

    // need a separate renderer for the axis, otherwise the same colours are used as for the first axis series
    setAxisRenderer(chart.getXYPlot(), 1, options.isSecondAxisBarChart(), options.hasSecondAxisDataPoints(),
            options.getSecondAxisLineWeight());

    setAxisLimits(rangeAxis2, options.getSecondAxisMinYValue(), options.getSecondAxisMaxYValue(),
            options.forceSecondAxisYRange());

    rangeAxis2.setAutoRangeIncludesZero(false);
}

From source file:com.romraider.logger.ecu.ui.handler.graph.GraphUpdateHandler.java

public synchronized void notifyConvertorUpdate(LoggerData updatedLoggerData) {
    if (chartMap.containsKey(updatedLoggerData)) {
        seriesMap.get(updatedLoggerData).clear();
        JFreeChart chart = chartMap.get(updatedLoggerData).getChart();
        chart.getXYPlot().getRangeAxis().setLabel(buildRangeAxisTitle(updatedLoggerData));
    }//  ww w. ja  va 2  s. c  om
}

From source file:adams.gui.visualization.jfreechart.chart.ScatterPlot.java

/**
 * Performs the actual generation of the chart.
 *
 * @param data   the data to use//from w w w . j av a 2 s .  c om
 * @return      the chart
 */
@Override
protected JFreeChart doGenerate(XYDataset data) {
    JFreeChart result = ChartFactory.createScatterPlot(m_Title, m_LabelX, m_LabelY, data,
            m_Orientation.getOrientation(), m_Legend, m_ToolTips, false);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    if (result.getXYPlot().getSeriesCount() == 2) {
        renderer.setSeriesLinesVisible(0, false);
        renderer.setSeriesLinesVisible(1, true);
        renderer.setSeriesShapesVisible(0, true);
        renderer.setSeriesShapesVisible(1, false);
        result.getXYPlot().setRenderer(renderer);
    }
    return result;
}

From source file:carfuzzy.Operations.java

public JFreeChart drawAggregation(FIS[] fis) {

    XYSeriesCollection aggregationDataset = new XYSeriesCollection();
    for (int i = 0; i < 4; i++) {
        aggregationDataset.addSeries(fis[i].getImplication());
    }//from  www .  j  a  v a2s.  co m
    //aggregationDataset.getSeries(0).setKey("Agjujugregation");
    JFreeChart chart = setToChart(aggregationDataset, "Aggregation");

    XYPlot plot = chart.getXYPlot();
    XYAreaRenderer renderer = new XYAreaRenderer();
    renderer.setSeriesVisibleInLegend(false, true);
    renderer.setSeriesItemLabelsVisible(0, false, true);
    renderer.setSeriesItemLabelsVisible(3, true);
    renderer.setPaint(Color.RED.darker(), true);
    plot.setRenderer(renderer);
    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setRange(0, 10);
    return chart;
}

From source file:com.algodefu.yeti.data.Pass.java

private void calculateEquityChartImg() throws IOException {
    int i = 0;/*from  ww w  . j a  va  2  s  . c o m*/
    double sum = 0;
    TimeSeries equity = new TimeSeries("Equity");

    // save values in temp array first, then use System.arraycopy to copy non empty values to this.equityArray
    double[][] tempEquityArr = new double[this.getTrades().length][4];

    for (Trade trade : this.getTrades()) {
        if (trade.getCloseDateTime() != null) {
            sum += trade.getProfit();
            equity.add(new Millisecond(Date.from(trade.getCloseDateTime().toInstant(ZoneOffset.UTC))), sum);
            tempEquityArr[i][0] = (double) trade.getCloseDateTime().toInstant(ZoneOffset.UTC).toEpochMilli();
            tempEquityArr[i][1] = sum;
            tempEquityArr[i][2] = trade.getTradeID();
            tempEquityArr[i][3] = trade.getProfit();
            i++;
        }
    }
    this.equityArray = new double[i][4];
    System.arraycopy(tempEquityArr, 0, this.equityArray, 0, i);

    TimeSeriesCollection dataset = new TimeSeriesCollection(equity);
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataset, false, false, false);
    chart.getXYPlot().getDomainAxis().setTickLabelsVisible(false);
    chart.setBorderVisible(true);
    chart.getXYPlot().setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
    chart.getXYPlot().getRenderer().setSeriesPaint(0, Color.blue);
    chart.getXYPlot().setBackgroundPaint(Color.white);
    chart.getXYPlot().setRangeGridlinePaint(Color.gray);
    chart.getXYPlot().setDomainGridlinePaint(Color.gray);
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        ChartUtilities.writeChartAsPNG(baos, chart, 320, 180);
        baos.flush();
        this.equityChartByteArray = baos.toByteArray();
    } catch (IOException e) {
        throw e;
    }

}