Search in sources :

Example 31 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class NewJFrame method drawBarGraph.

/**
 * @param dataset Creates bar graph
 */
public void drawBarGraph(DefaultCategoryDataset dataset) {
    CategoryPlot plot = (CategoryPlot) barChart.getPlot();
    plot.getRenderer().setSeriesPaint(0, Color.BLUE);
    plot.getRenderer().setSeriesPaint(1, Color.RED);
    ChartPanel chartpanel = new ChartPanel(barChart);
    graph_panel.removeAll();
    graph_panel.add(chartpanel, BorderLayout.CENTER);
    graph_panel.revalidate();
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 32 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class BarChartDemo1 method createChart.

/**
 * Creates a sample chart.
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart("Performance: JFreeSVG vs Batik", null, /* x-axis label*/
    "Milliseconds", /* y-axis label */
    dataset);
    chart.addSubtitle(new TextTitle("Time to generate 1000 charts in SVG " + "format (lower bars = better performance)"));
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    // ******************************************************************
    // More than 150 demo applications are included with the JFreeChart
    // Developer Guide...for more information, see:
    // 
    // >   http://www.object-refinery.com/jfreechart/guide.html
    // 
    // ******************************************************************
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    chart.getLegend().setFrame(BlockBorder.NONE);
    return chart;
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) NumberAxis(org.jfree.chart.axis.NumberAxis) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 33 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class DefaultPlotEditor method createPlotTabs.

protected JTabbedPane createPlotTabs(Plot plot) {
    JTabbedPane tabs = new JTabbedPane();
    tabs.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    Axis domainAxis = null;
    if (plot instanceof CategoryPlot) {
        domainAxis = ((CategoryPlot) plot).getDomainAxis();
    } else if (plot instanceof XYPlot) {
        domainAxis = ((XYPlot) plot).getDomainAxis();
    }
    this.domainAxisPropertyPanel = DefaultAxisEditor.getInstance(domainAxis);
    if (this.domainAxisPropertyPanel != null) {
        this.domainAxisPropertyPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        tabs.add(localizationResources.getString("Domain_Axis"), this.domainAxisPropertyPanel);
    }
    Axis rangeAxis = null;
    if (plot instanceof CategoryPlot) {
        rangeAxis = ((CategoryPlot) plot).getRangeAxis();
    } else if (plot instanceof XYPlot) {
        rangeAxis = ((XYPlot) plot).getRangeAxis();
    } else if (plot instanceof PolarPlot) {
        rangeAxis = ((PolarPlot) plot).getAxis();
    }
    this.rangeAxisPropertyPanel = DefaultAxisEditor.getInstance(rangeAxis);
    if (this.rangeAxisPropertyPanel != null) {
        this.rangeAxisPropertyPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        tabs.add(localizationResources.getString("Range_Axis"), this.rangeAxisPropertyPanel);
    }
    // dmo: added this panel for colorbar control. (start dmo additions)
    ColorBar colorBar = null;
    if (plot instanceof ContourPlot) {
        colorBar = ((ContourPlot) plot).getColorBar();
    }
    this.colorBarAxisPropertyPanel = DefaultColorBarEditor.getInstance(colorBar);
    if (this.colorBarAxisPropertyPanel != null) {
        this.colorBarAxisPropertyPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        tabs.add(localizationResources.getString("Color_Bar"), this.colorBarAxisPropertyPanel);
    }
    return tabs;
}
Also used : ContourPlot(org.jfree.chart.plot.ContourPlot) XYPlot(org.jfree.chart.plot.XYPlot) JTabbedPane(javax.swing.JTabbedPane) PolarPlot(org.jfree.chart.plot.PolarPlot) Axis(org.jfree.chart.axis.Axis) CategoryPlot(org.jfree.chart.plot.CategoryPlot) ColorBar(org.jfree.chart.axis.ColorBar)

Example 34 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class DefaultPlotEditor method createPlotPanel.

protected JPanel createPlotPanel(Plot plot) {
    this.plotInsets = plot.getInsets();
    this.backgroundPaintSample = new PaintSample(plot.getBackgroundPaint());
    this.outlineStrokeSample = new StrokeSample(plot.getOutlineStroke());
    this.outlinePaintSample = new PaintSample(plot.getOutlinePaint());
    if (plot instanceof CategoryPlot) {
        this.plotOrientation = ((CategoryPlot) plot).getOrientation();
    } else if (plot instanceof XYPlot) {
        this.plotOrientation = ((XYPlot) plot).getOrientation();
    }
    if (plot instanceof CategoryPlot) {
        CategoryItemRenderer renderer = ((CategoryPlot) plot).getRenderer();
        if (renderer instanceof LineAndShapeRenderer) {
            LineAndShapeRenderer r = (LineAndShapeRenderer) renderer;
            this.drawLines = BooleanUtilities.valueOf(r.getBaseLinesVisible());
            this.drawShapes = BooleanUtilities.valueOf(r.getBaseShapesVisible());
        }
    } else if (plot instanceof XYPlot) {
        XYItemRenderer renderer = ((XYPlot) plot).getRenderer();
        if (renderer instanceof StandardXYItemRenderer) {
            StandardXYItemRenderer r = (StandardXYItemRenderer) renderer;
            this.drawLines = BooleanUtilities.valueOf(r.getPlotLines());
            this.drawShapes = BooleanUtilities.valueOf(r.getBaseShapesVisible());
        }
    }
    setLayout(new BorderLayout());
    this.availableStrokeSamples = new StrokeSample[4];
    this.availableStrokeSamples[0] = new StrokeSample(null);
    this.availableStrokeSamples[1] = new StrokeSample(new BasicStroke(1.0f));
    this.availableStrokeSamples[2] = new StrokeSample(new BasicStroke(2.0f));
    this.availableStrokeSamples[3] = new StrokeSample(new BasicStroke(3.0f));
    // create a panel for the settings...
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), plot.getPlotType() + localizationResources.getString(":")));
    JPanel general = new JPanel(new BorderLayout());
    general.setBorder(BorderFactory.createTitledBorder(localizationResources.getString("General")));
    JPanel interior = new JPanel(new LCBLayout(7));
    interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    // interior.add(new JLabel(localizationResources.getString("Insets")));
    // JButton button = new JButton(
    // localizationResources.getString("Edit...")
    // );
    // button.setActionCommand("Insets");
    // button.addActionListener(this);
    // 
    // this.insetsTextField = new InsetsTextField(this.plotInsets);
    // this.insetsTextField.setEnabled(false);
    // interior.add(this.insetsTextField);
    // interior.add(button);
    interior.add(new JLabel(localizationResources.getString("Outline_stroke")));
    JButton button = new JButton(localizationResources.getString("Select..."));
    button.setActionCommand("OutlineStroke");
    button.addActionListener(this);
    interior.add(this.outlineStrokeSample);
    interior.add(button);
    interior.add(new JLabel(localizationResources.getString("Outline_Paint")));
    button = new JButton(localizationResources.getString("Select..."));
    button.setActionCommand("OutlinePaint");
    button.addActionListener(this);
    interior.add(this.outlinePaintSample);
    interior.add(button);
    interior.add(new JLabel(localizationResources.getString("Background_paint")));
    button = new JButton(localizationResources.getString("Select..."));
    button.setActionCommand("BackgroundPaint");
    button.addActionListener(this);
    interior.add(this.backgroundPaintSample);
    interior.add(button);
    if (this.plotOrientation != null) {
        boolean isVertical = this.plotOrientation.equals(PlotOrientation.VERTICAL);
        int index = isVertical ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL;
        interior.add(new JLabel(localizationResources.getString("Orientation")));
        this.orientationCombo = new JComboBox(orientationNames);
        this.orientationCombo.setSelectedIndex(index);
        this.orientationCombo.setActionCommand("Orientation");
        this.orientationCombo.addActionListener(this);
        interior.add(new JPanel());
        interior.add(this.orientationCombo);
    }
    if (this.drawLines != null) {
        interior.add(new JLabel(localizationResources.getString("Draw_lines")));
        this.drawLinesCheckBox = new JCheckBox();
        this.drawLinesCheckBox.setSelected(this.drawLines.booleanValue());
        this.drawLinesCheckBox.setActionCommand("DrawLines");
        this.drawLinesCheckBox.addActionListener(this);
        interior.add(new JPanel());
        interior.add(this.drawLinesCheckBox);
    }
    if (this.drawShapes != null) {
        interior.add(new JLabel(localizationResources.getString("Draw_shapes")));
        this.drawShapesCheckBox = new JCheckBox();
        this.drawShapesCheckBox.setSelected(this.drawShapes.booleanValue());
        this.drawShapesCheckBox.setActionCommand("DrawShapes");
        this.drawShapesCheckBox.addActionListener(this);
        interior.add(new JPanel());
        interior.add(this.drawShapesCheckBox);
    }
    general.add(interior, BorderLayout.NORTH);
    JPanel appearance = new JPanel(new BorderLayout());
    appearance.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    appearance.add(general, BorderLayout.NORTH);
    JTabbedPane tabs = createPlotTabs(plot);
    tabs.add(localizationResources.getString("Appearance"), appearance);
    panel.add(tabs);
    return panel;
}
Also used : BasicStroke(java.awt.BasicStroke) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) JPanel(javax.swing.JPanel) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) JComboBox(javax.swing.JComboBox) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Paint(java.awt.Paint) LCBLayout(org.jfree.layout.LCBLayout) JCheckBox(javax.swing.JCheckBox) XYPlot(org.jfree.chart.plot.XYPlot) BorderLayout(java.awt.BorderLayout) PaintSample(org.jfree.ui.PaintSample) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) StrokeSample(org.jfree.ui.StrokeSample) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer)

Example 35 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class BarChartTest method testReplaceDataset.

/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
@Test
public void testReplaceDataset() {
    // create a dataset...
    Number[][] data = new Integer[][] { { new Integer(-30), new Integer(-20) }, { new Integer(-10), new Integer(10) }, { new Integer(20), new Integer(30) } };
    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data);
    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30);
    assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30);
}
Also used : CategoryDataset(org.jfree.data.category.CategoryDataset) ValueAxis(org.jfree.chart.axis.ValueAxis) Range(org.jfree.data.Range) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Test(org.junit.Test)

Aggregations

CategoryPlot (org.jfree.chart.plot.CategoryPlot)190 JFreeChart (org.jfree.chart.JFreeChart)94 CategoryAxis (org.jfree.chart.axis.CategoryAxis)88 NumberAxis (org.jfree.chart.axis.NumberAxis)80 Test (org.junit.Test)72 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)44 CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)36 ValueAxis (org.jfree.chart.axis.ValueAxis)35 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)32 CategoryDataset (org.jfree.data.category.CategoryDataset)29 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)27 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)24 Paint (java.awt.Paint)23 DefaultBoxAndWhiskerCategoryDataset (org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset)16 LegendItem (org.jfree.chart.LegendItem)15 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)14 RectangleInsets (org.jfree.ui.RectangleInsets)13 XYPlot (org.jfree.chart.plot.XYPlot)12 ArrayList (java.util.ArrayList)11 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)11