Search in sources :

Example 1 with StandardCategoryURLGenerator

use of org.jfree.chart.urls.StandardCategoryURLGenerator in project pentaho-platform by pentaho.

the class JFreeChartEngine method createBarChart.

private static JFreeChart createBarChart(final CategoryDatasetChartDefinition chartDefinition) {
    // TODO Make the following accessible from the chartDefinition
    String categoryAxisLabel = null;
    String valueAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------
    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();
    PlotOrientation orientation = chartDefinition.getOrientation();
    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
    BarRenderer renderer = null;
    // Determine the type of renderer to use
    if (chartDefinition.isStacked() || chartDefinition.isThreeD()) {
        if (chartDefinition.isStacked() && chartDefinition.isThreeD()) {
            renderer = new StackedBarRenderer3D();
        } else if (chartDefinition.isStacked()) {
            renderer = new StackedBarRenderer();
        } else {
            renderer = new BarRenderer3D();
        }
    } else {
        renderer = new BarRenderer();
    }
    if (orientation == PlotOrientation.HORIZONTAL) {
        ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
        renderer.setPositiveItemLabelPosition(position1);
        ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);
        renderer.setNegativeItemLabelPosition(position2);
    } else if (orientation == PlotOrientation.VERTICAL) {
        ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
        renderer.setPositiveItemLabelPosition(position1);
        ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
        renderer.setNegativeItemLabelPosition(position2);
    }
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }
    if (chartDefinition.getMaxBarWidth() != null) {
        renderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue());
    }
    CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) NumberAxis(org.jfree.chart.axis.NumberAxis) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) StackedBarRenderer3D(org.jfree.chart.renderer.category.StackedBarRenderer3D) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) StandardCategoryURLGenerator(org.jfree.chart.urls.StandardCategoryURLGenerator) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) StackedBarRenderer3D(org.jfree.chart.renderer.category.StackedBarRenderer3D) BarRenderer3D(org.jfree.chart.renderer.category.BarRenderer3D) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) ValueAxis(org.jfree.chart.axis.ValueAxis) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition)

Example 2 with StandardCategoryURLGenerator

use of org.jfree.chart.urls.StandardCategoryURLGenerator in project pentaho-platform by pentaho.

the class JFreeChartEngine method createLineChart.

private static JFreeChart createLineChart(final CategoryDatasetChartDefinition chartDefinition) {
    // TODO Make the following accessible from the chartDefinition
    String categoryAxisLabel = null;
    String valueAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------
    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();
    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
    LineAndShapeRenderer renderer = chartDefinition.isThreeD() ? new LineRenderer3D() : new LineAndShapeRenderer(true, false);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }
    renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth()));
    renderer.setShapesVisible(chartDefinition.isMarkersVisible());
    renderer.setBaseShapesFilled(chartDefinition.isMarkersVisible());
    CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;
}
Also used : XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) LineRenderer3D(org.jfree.chart.renderer.category.LineRenderer3D) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) ValueAxis(org.jfree.chart.axis.ValueAxis) StandardCategoryURLGenerator(org.jfree.chart.urls.StandardCategoryURLGenerator) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart)

Example 3 with StandardCategoryURLGenerator

use of org.jfree.chart.urls.StandardCategoryURLGenerator in project SIMVA-SoS by SESoS.

the class AreaChartTest method testSetSeriesURLGenerator.

/**
 * Check that setting a URL generator for a series does override the
 * default generator.
 */
@Test
public void testSetSeriesURLGenerator() {
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    CategoryItemRenderer renderer = plot.getRenderer();
    StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator();
    renderer.setSeriesItemURLGenerator(0, url1);
    CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0);
    assertSame(url2, url1);
}
Also used : CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryURLGenerator(org.jfree.chart.urls.CategoryURLGenerator) StandardCategoryURLGenerator(org.jfree.chart.urls.StandardCategoryURLGenerator) StandardCategoryURLGenerator(org.jfree.chart.urls.StandardCategoryURLGenerator) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Test(org.junit.Test)

Example 4 with StandardCategoryURLGenerator

use of org.jfree.chart.urls.StandardCategoryURLGenerator in project SIMVA-SoS by SESoS.

the class AbstractCategoryItemRendererTest method testEquals.

/**
 * Checks that all fields are distinguished.
 */
@Test
public void testEquals() {
    BarRenderer r1 = new BarRenderer();
    BarRenderer r2 = new BarRenderer();
    assertEquals(r1, r2);
    // the plot field is NOT tested
    // toolTipGenerator
    r1.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    assertFalse(r1.equals(r2));
    r2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    assertTrue(r1.equals(r2));
    // toolTipGeneratorList
    r1.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
    assertFalse(r1.equals(r2));
    r2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
    assertTrue(r1.equals(r2));
    // baseToolTipGenerator
    r1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{2}", NumberFormat.getInstance()));
    assertFalse(r1.equals(r2));
    r2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{2}", NumberFormat.getInstance()));
    assertTrue(r1.equals(r2));
    // itemLabelGenerator
    r1.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    assertFalse(r1.equals(r2));
    r2.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    assertTrue(r1.equals(r2));
    // itemLabelGeneratorList
    r1.setSeriesItemLabelGenerator(1, new StandardCategoryItemLabelGenerator());
    assertFalse(r1.equals(r2));
    r2.setSeriesItemLabelGenerator(1, new StandardCategoryItemLabelGenerator());
    assertTrue(r1.equals(r2));
    // baseItemLabelGenerator
    r1.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getInstance()));
    assertFalse(r1.equals(r2));
    r2.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getInstance()));
    assertTrue(r1.equals(r2));
    // urlGenerator
    r1.setItemURLGenerator(new StandardCategoryURLGenerator());
    assertFalse(r1.equals(r2));
    r2.setItemURLGenerator(new StandardCategoryURLGenerator());
    assertTrue(r1.equals(r2));
    // urlGeneratorList
    r1.setSeriesItemURLGenerator(1, new StandardCategoryURLGenerator());
    assertFalse(r1.equals(r2));
    r2.setSeriesItemURLGenerator(1, new StandardCategoryURLGenerator());
    assertTrue(r1.equals(r2));
    // baseItemURLGenerator
    r1.setBaseItemURLGenerator(new StandardCategoryURLGenerator("abc.html"));
    assertFalse(r1.equals(r2));
    r2.setBaseItemURLGenerator(new StandardCategoryURLGenerator("abc.html"));
    assertTrue(r1.equals(r2));
    // legendItemLabelGenerator
    r1.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator("XYZ"));
    assertFalse(r1.equals(r2));
    r2.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator("XYZ"));
    assertTrue(r1.equals(r2));
    // legendItemToolTipGenerator
    r1.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("ToolTip"));
    assertFalse(r1.equals(r2));
    r2.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("ToolTip"));
    assertTrue(r1.equals(r2));
    // legendItemURLGenerator
    r1.setLegendItemURLGenerator(new StandardCategorySeriesLabelGenerator("URL"));
    assertFalse(r1.equals(r2));
    r2.setLegendItemURLGenerator(new StandardCategorySeriesLabelGenerator("URL"));
    assertTrue(r1.equals(r2));
}
Also used : StandardCategoryItemLabelGenerator(org.jfree.chart.labels.StandardCategoryItemLabelGenerator) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) StandardCategoryURLGenerator(org.jfree.chart.urls.StandardCategoryURLGenerator) StandardCategorySeriesLabelGenerator(org.jfree.chart.labels.StandardCategorySeriesLabelGenerator) Test(org.junit.Test)

Example 5 with StandardCategoryURLGenerator

use of org.jfree.chart.urls.StandardCategoryURLGenerator in project SIMVA-SoS by SESoS.

the class SpiderWebPlotTest method testEquals.

/**
 * Some checks for the equals() method.
 */
@Test
public void testEquals() {
    SpiderWebPlot p1 = new SpiderWebPlot(new DefaultCategoryDataset());
    SpiderWebPlot p2 = new SpiderWebPlot(new DefaultCategoryDataset());
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));
    // dataExtractOrder
    p1.setDataExtractOrder(TableOrder.BY_COLUMN);
    assertFalse(p1.equals(p2));
    p2.setDataExtractOrder(TableOrder.BY_COLUMN);
    assertTrue(p1.equals(p2));
    // headPercent
    p1.setHeadPercent(0.321);
    assertFalse(p1.equals(p2));
    p2.setHeadPercent(0.321);
    assertTrue(p1.equals(p2));
    // interiorGap
    p1.setInteriorGap(0.123);
    assertFalse(p1.equals(p2));
    p2.setInteriorGap(0.123);
    assertTrue(p1.equals(p2));
    // startAngle
    p1.setStartAngle(0.456);
    assertFalse(p1.equals(p2));
    p2.setStartAngle(0.456);
    assertTrue(p1.equals(p2));
    // direction
    p1.setDirection(Rotation.ANTICLOCKWISE);
    assertFalse(p1.equals(p2));
    p2.setDirection(Rotation.ANTICLOCKWISE);
    assertTrue(p1.equals(p2));
    // maxValue
    p1.setMaxValue(123.4);
    assertFalse(p1.equals(p2));
    p2.setMaxValue(123.4);
    assertTrue(p1.equals(p2));
    // legendItemShape
    p1.setLegendItemShape(new Rectangle(1, 2, 3, 4));
    assertFalse(p1.equals(p2));
    p2.setLegendItemShape(new Rectangle(1, 2, 3, 4));
    assertTrue(p1.equals(p2));
    // seriesPaint
    p1.setSeriesPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.white));
    assertFalse(p1.equals(p2));
    p2.setSeriesPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.white));
    assertTrue(p1.equals(p2));
    // seriesPaintList
    p1.setSeriesPaint(1, new GradientPaint(1.0f, 2.0f, Color.yellow, 3.0f, 4.0f, Color.white));
    assertFalse(p1.equals(p2));
    p2.setSeriesPaint(1, new GradientPaint(1.0f, 2.0f, Color.yellow, 3.0f, 4.0f, Color.white));
    assertTrue(p1.equals(p2));
    // baseSeriesPaint
    p1.setBaseSeriesPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.black));
    assertFalse(p1.equals(p2));
    p2.setBaseSeriesPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.black));
    assertTrue(p1.equals(p2));
    // seriesOutlinePaint
    p1.setSeriesOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.black));
    assertFalse(p1.equals(p2));
    p2.setSeriesOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.black));
    assertTrue(p1.equals(p2));
    // seriesOutlinePaintList
    p1.setSeriesOutlinePaint(1, new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.green));
    assertFalse(p1.equals(p2));
    p2.setSeriesOutlinePaint(1, new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.green));
    assertTrue(p1.equals(p2));
    // baseSeriesOutlinePaint
    p1.setBaseSeriesOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.cyan, 3.0f, 4.0f, Color.green));
    assertFalse(p1.equals(p2));
    p2.setBaseSeriesOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.cyan, 3.0f, 4.0f, Color.green));
    assertTrue(p1.equals(p2));
    // seriesOutlineStroke
    BasicStroke s = new BasicStroke(1.23f);
    p1.setSeriesOutlineStroke(s);
    assertFalse(p1.equals(p2));
    p2.setSeriesOutlineStroke(s);
    assertTrue(p1.equals(p2));
    // seriesOutlineStrokeList
    p1.setSeriesOutlineStroke(1, s);
    assertFalse(p1.equals(p2));
    p2.setSeriesOutlineStroke(1, s);
    assertTrue(p1.equals(p2));
    // baseSeriesOutlineStroke
    p1.setBaseSeriesOutlineStroke(s);
    assertFalse(p1.equals(p2));
    p2.setBaseSeriesOutlineStroke(s);
    assertTrue(p1.equals(p2));
    // webFilled
    p1.setWebFilled(false);
    assertFalse(p1.equals(p2));
    p2.setWebFilled(false);
    assertTrue(p1.equals(p2));
    // axisLabelGap
    p1.setAxisLabelGap(0.11);
    assertFalse(p1.equals(p2));
    p2.setAxisLabelGap(0.11);
    assertTrue(p1.equals(p2));
    // labelFont
    p1.setLabelFont(new Font("Serif", Font.PLAIN, 9));
    assertFalse(p1.equals(p2));
    p2.setLabelFont(new Font("Serif", Font.PLAIN, 9));
    assertTrue(p1.equals(p2));
    // labelPaint
    p1.setLabelPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertFalse(p1.equals(p2));
    p2.setLabelPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertTrue(p1.equals(p2));
    // labelGenerator
    p1.setLabelGenerator(new StandardCategoryItemLabelGenerator("XYZ: {0}", new DecimalFormat("0.000")));
    assertFalse(p1.equals(p2));
    p2.setLabelGenerator(new StandardCategoryItemLabelGenerator("XYZ: {0}", new DecimalFormat("0.000")));
    assertTrue(p1.equals(p2));
    // toolTipGenerator
    p1.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    assertFalse(p1.equals(p2));
    p2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    assertTrue(p1.equals(p2));
    // urlGenerator
    p1.setURLGenerator(new StandardCategoryURLGenerator());
    assertFalse(p1.equals(p2));
    p2.setURLGenerator(new StandardCategoryURLGenerator());
    assertTrue(p1.equals(p2));
    // axisLinePaint
    p1.setAxisLinePaint(Color.red);
    assertFalse(p1.equals(p2));
    p2.setAxisLinePaint(Color.red);
    assertTrue(p1.equals(p2));
    // axisLineStroke
    p1.setAxisLineStroke(new BasicStroke(1.1f));
    assertFalse(p1.equals(p2));
    p2.setAxisLineStroke(new BasicStroke(1.1f));
    assertTrue(p1.equals(p2));
}
Also used : BasicStroke(java.awt.BasicStroke) StandardCategoryItemLabelGenerator(org.jfree.chart.labels.StandardCategoryItemLabelGenerator) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) DecimalFormat(java.text.DecimalFormat) Rectangle(java.awt.Rectangle) GradientPaint(java.awt.GradientPaint) StandardCategoryURLGenerator(org.jfree.chart.urls.StandardCategoryURLGenerator) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Font(java.awt.Font) Test(org.junit.Test)

Aggregations

StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)27 CategoryPlot (org.jfree.chart.plot.CategoryPlot)24 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)15 CategoryAxis (org.jfree.chart.axis.CategoryAxis)14 ValueAxis (org.jfree.chart.axis.ValueAxis)13 Test (org.junit.Test)13 CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)12 NumberAxis (org.jfree.chart.axis.NumberAxis)10 CategoryURLGenerator (org.jfree.chart.urls.CategoryURLGenerator)10 JFreeChart (org.jfree.chart.JFreeChart)4 ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)4 StackedBarRenderer (org.jfree.chart.renderer.category.StackedBarRenderer)4 StackedBarRenderer3D (org.jfree.chart.renderer.category.StackedBarRenderer3D)4 CategoryAxis3D (org.jfree.chart.axis.CategoryAxis3D)3 NumberAxis3D (org.jfree.chart.axis.NumberAxis3D)3 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)3 BarRenderer3D (org.jfree.chart.renderer.category.BarRenderer3D)3 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)3 LineRenderer3D (org.jfree.chart.renderer.category.LineRenderer3D)3 StackedAreaRenderer (org.jfree.chart.renderer.category.StackedAreaRenderer)3