Example usage for org.jfree.chart ChartPanel getChart

List of usage examples for org.jfree.chart ChartPanel getChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartPanel getChart.

Prototype

public JFreeChart getChart() 

Source Link

Document

Returns the chart contained in the panel.

Usage

From source file:fi.smaa.jsmaa.gui.components.ValueFunctionMouseListener.java

public ValueFunctionMouseListener(ChartPanel chartPanel, ScaleCriterion criterion, Component parent) {
    JFreeChart chart = chartPanel.getChart();
    this.chartPanel = chartPanel;
    plot = chart.getXYPlot();// w w  w  . j  av  a  2 s . c  o  m
    this.crit = criterion;
    this.parent = parent;
}

From source file:com.googlecode.logVisualizer.chart.TotalConsumptionPie.java

@Override
protected ChartPanel createChartPanel() {
    final ChartPanel panel = super.createChartPanel();
    final PiePlot plot = (PiePlot) panel.getChart().getPlot();

    plot.setSectionPaint("Eating", DEFAULT_COLORS[0]);
    plot.setSectionPaint("Drinking", DEFAULT_COLORS[1]);
    plot.setSectionPaint("Other", DEFAULT_COLORS[2]);
    plot.setSectionPaint("Rollover", DEFAULT_COLORS[3]);

    return panel;
}

From source file:com.googlecode.logVisualizer.chart.StatDevelopmentLineChart.java

@Override
protected ChartPanel createChartPanel() {
    final ChartPanel panel = super.createChartPanel();
    final XYPlot plot = (XYPlot) panel.getChart().getPlot();

    for (final DayChange dc : getLogData().getDayChanges()) {
        final ValueMarker day = new ValueMarker(dc.getTurnNumber());
        day.setLabel("Day " + dc.getDayNumber());
        day.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        day.setLabelTextAnchor(TextAnchor.TOP_LEFT);
        day.setStroke(new BasicStroke(2));
        day.setPaint(new Color(175, 175, 255));
        plot.addDomainMarker(day);/*from www.  ja  v a  2 s .c om*/
    }

    return panel;
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * /*from   w w w  . j a  v  a 2  s.co  m*/
 * Domain and Range axes need to share the same unit (e.g. mm)
 * 
 * @param myChart
 * @return
 */
public static double calcWidthToHeight(ChartPanel myChart, double chartHeight) {
    makeChartResizable(myChart);
    // paint on a ghost panel
    JPanel parent = (JPanel) myChart.getParent();
    JPanel p = new JPanel();
    p.removeAll();
    p.add(myChart, BorderLayout.CENTER);
    p.setBounds(myChart.getBounds());
    myChart.paintImmediately(myChart.getBounds());
    p.removeAll();
    parent.add(myChart);

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;

    return width;
}

From source file:picocash.components.panel.statistic.AbstractPieStatisticComponent.java

private final void init() {
    this.title = getTitle();
    this.dataset = new DefaultPieDataset();
    this.chartPanel = new JXPanel(new MigLayout("fill, insets 0 0 0 0"));
    final JFreeChart piechart = ChartFactory.createPieChart(title, dataset, true, true, Locale.getDefault());
    ((PiePlot) piechart.getPlot()).setLabelGenerator(null);
    piechart.setBorderVisible(false);/*from www  .j  a  v  a2  s.  c o  m*/
    piechart.setAntiAlias(true);
    ChartPanel chart = new ChartPanel(piechart, 300, 300, 200, 200, 400, 400, false, false, false, false, false,
            true);
    chart.getChart().getPlot().setBackgroundAlpha(0);
    chart.getChart().getPlot().setOutlineVisible(false);
    this.chartPanel.setOpaque(false);
    this.chartPanel.add(chart, "growx, aligny top");
}

From source file:com.googlecode.logVisualizer.chart.MPGainedSpentPerTurnXYBarChart.java

/**
 * Method overridden to make the MP spent bar colour use a bit of alpha,
 * otherwise MP gains below MP spent wouldn't be viewable.
 *///from w w  w.  j a v a  2s. c  o m
@Override
protected ChartPanel createChartPanel() {
    final ChartPanel panel = super.createChartPanel();
    final XYPlot plot = (XYPlot) panel.getChart().getPlot();
    final XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    final XYDataset dataset = plot.getDataset();

    for (int i = 0; i < dataset.getSeriesCount(); i++)
        if (dataset.getSeriesKey(i).equals("MP spent"))
            renderer.setSeriesPaint(i, new Color(255, 80, 80, 200));
        else if (dataset.getSeriesKey(i).equals("MP gained"))
            renderer.setSeriesPaint(i, new Color(100, 100, 255));

    return panel;
}

From source file:picocash.components.panel.statistic.IncomeByCategoryStatistic.java

private void init() {
    this.title = "Income";
    this.dataset = new DefaultPieDataset();
    this.chartPanel = new JXPanel(new MigLayout("fill, insets 0 0 0 0"));

    final JFreeChart piechart = ChartFactory.createPieChart(title, dataset, true, true, Locale.getDefault());
    piechart.setBorderVisible(false);/* w ww.  j  a  va 2  s  . c om*/
    piechart.setAntiAlias(true);
    ((PiePlot) piechart.getPlot()).setLabelGenerator(null);

    ChartPanel chart = new ChartPanel(piechart, 300, 300, 200, 200, 400, 400, false, false, false, false, false,
            true);

    chart.getChart().getPlot().setBackgroundAlpha(0);
    chart.getChart().getPlot().setOutlineVisible(false);

    this.chartPanel.setOpaque(false);
    this.chartPanel.add(chart, "aligny top");
}

From source file:picocash.components.panel.statistic.ExpenseByCategoryStatistic.java

private void init() {
    this.title = "Expense";
    this.dataset = new DefaultPieDataset();
    this.chartPanel = new JXPanel(new MigLayout("fill, insets 0 0 0 0"));
    final JFreeChart piechart = ChartFactory.createPieChart(title, dataset, true, true, Locale.getDefault());
    ((PiePlot) piechart.getPlot()).setLabelGenerator(null);

    piechart.setBorderVisible(false);/*from   w w  w .  j  a v  a  2  s.  c  om*/
    piechart.setAntiAlias(true);
    ChartPanel chart = new ChartPanel(piechart, 300, 300, 200, 200, 400, 400, false, false, false, false, false,
            true);

    chart.getChart().getPlot().setBackgroundAlpha(0);
    chart.getChart().getPlot().setOutlineVisible(false);

    this.chartPanel.setOpaque(false);
    this.chartPanel.add(chart, "growx, aligny top");
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * Returns dimensions for limiting factor width or height
 * //from  w w w  . j av a2 s  .  c om
 * @param myChart
 * @return
 */
public static Dimension calcMaxSize(ChartPanel myChart, double chartWidth, double chartHeight) {
    makeChartResizable(myChart);
    // paint on a ghost panel
    JPanel parent = (JPanel) myChart.getParent();
    JPanel p = new JPanel();
    p.removeAll();
    p.add(myChart, BorderLayout.CENTER);
    p.setBounds(myChart.getBounds());
    myChart.paintImmediately(myChart.getBounds());
    p.removeAll();
    parent.add(myChart);

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calculatig width for max height

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;
    // if width is higher than given chartWidth then calc height for chartWidth
    if (width > chartWidth) {
        // calc right plot size with axis dim.
        // real plot width is given by factor;
        realPW = chartWidth - titleWidth;

        // real plot height can be calculated by
        realPH = realPW / x.getLength() * y.getLength();

        double height = realPH + titleHeight;
        // Return size
        return new Dimension((int) chartWidth, (int) height);
    } else {
        // Return size
        return new Dimension((int) width, (int) chartHeight);
    }
}

From source file:com.googlecode.logVisualizer.chart.ConsumptionBarChart.java

@Override
protected ChartPanel createChartPanel() {
    final ChartPanel panel = super.createChartPanel();
    final CategoryPlot plot = (CategoryPlot) panel.getChart().getPlot();
    final StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    final CategoryDataset dataset = plot.getDataset();

    for (int i = 0; i < dataset.getRowCount(); i++)
        if (dataset.getRowKey(i).equals("Food"))
            renderer.setSeriesPaint(i, new Color(255, 80, 80));
        else if (dataset.getRowKey(i).equals("Booze"))
            renderer.setSeriesPaint(i, new Color(100, 100, 255));
        else if (dataset.getRowKey(i).equals("Spleen"))
            renderer.setSeriesPaint(i, new Color(80, 255, 80));
        else if (dataset.getRowKey(i).equals("Other"))
            renderer.setSeriesPaint(i, Color.LIGHT_GRAY);

    return panel;
}