Search in sources :

Example 61 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CombinedXYPlotDemo1 method createCombinedChart.

/**
 * Creates an overlaid chart.
 *
 * @return The chart.
 */
private static JFreeChart createCombinedChart() {
    // create plot ...
    IntervalXYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    renderer1.setSeriesStroke(0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesPaint(0, Color.blue);
    DateAxis domainAxis = new DateAxis("Year");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.02);
    ValueAxis rangeAxis = new NumberAxis("$billion");
    XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);
    // add a second dataset and renderer...
    IntervalXYDataset data2 = createDataset2();
    XYBarRenderer renderer2 = new XYBarRenderer() {

        public Paint getItemPaint(int series, int item) {
            XYDataset dataset = getPlot().getDataset();
            if (dataset.getYValue(series, item) >= 0.0) {
                return Color.red;
            } else {
                return Color.green;
            }
        }
    };
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setDrawBarOutline(false);
    renderer2.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);
    CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis);
    cplot.add(plot1, 3);
    cplot.add(plot2, 2);
    cplot.setGap(8.0);
    cplot.setDomainGridlinePaint(Color.white);
    cplot.setDomainGridlinesVisible(true);
    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1", JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
    chart.setBackgroundPaint(Color.white);
    LegendTitle legend = new LegendTitle(cplot);
    chart.addSubtitle(legend);
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) DecimalFormat(java.text.DecimalFormat) CombinedXYPlot(org.jfree.experimental.chart.plot.CombinedXYPlot) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) CombinedXYPlot(org.jfree.experimental.chart.plot.CombinedXYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYDataset(org.jfree.data.xy.XYDataset) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) SimpleDateFormat(java.text.SimpleDateFormat) XYBarRenderer(org.jfree.chart.renderer.xy.XYBarRenderer)

Example 62 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class PolarPlotTest method testTranslateToJava2D_NumberAxisAndMargin.

@Test
public void testTranslateToJava2D_NumberAxisAndMargin() {
    Rectangle2D dataArea = new Rectangle2D.Double(10.0, 10.0, 80.0, 80.0);
    ValueAxis axis = new NumberAxis();
    axis.setRange(-2.0, 2.0);
    PolarPlot plot = new PolarPlot(null, axis, null);
    plot.setAngleOffset(0.0);
    Point point = plot.translateToJava2D(0.0, 10.0, axis, dataArea);
    assertEquals(110.0, point.getX(), 0.5);
    assertEquals(50.0, point.getY(), 0.5);
    point = plot.translateToJava2D(90.0, 5.0, axis, dataArea);
    assertEquals(50.0, point.getX(), 0.5);
    assertEquals(85.0, point.getY(), 0.5);
    point = plot.translateToJava2D(45.0, 20.0, axis, dataArea);
    assertEquals(128.0, point.getX(), 0.5);
    assertEquals(128.0, point.getY(), 0.5);
    point = plot.translateToJava2D(135.0, 20.0, axis, dataArea);
    assertEquals(-28.0, point.getX(), 0.5);
    assertEquals(128.0, point.getY(), 0.5);
    point = plot.translateToJava2D(225.0, 15.0, axis, dataArea);
    assertEquals(-10.0, point.getX(), 0.5);
    assertEquals(-10.0, point.getY(), 0.5);
    point = plot.translateToJava2D(315.0, 15.0, axis, dataArea);
    assertEquals(110.0, point.getX(), 0.5);
    assertEquals(-10.0, point.getY(), 0.5);
    point = plot.translateToJava2D(21.0, 11.5, axis, dataArea);
    assertEquals(113.0, point.getX(), 0.5);
    assertEquals(74.0, point.getY(), 0.5);
    point = plot.translateToJava2D(162.0, 7.0, axis, dataArea);
    assertEquals(7.0, point.getX(), 0.5);
    assertEquals(64.0, point.getY(), 0.5);
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) Rectangle2D(java.awt.geom.Rectangle2D) Point(java.awt.Point) Test(org.junit.Test)

Example 63 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testAxisLocationIndices.

@Test
public void testAxisLocationIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    CategoryAxis xAxis2 = new CategoryAxis("X2");
    NumberAxis yAxis2 = new NumberAxis("Y2");
    plot.setDomainAxis(99, xAxis2);
    plot.setRangeAxis(99, yAxis2);
    plot.setDomainAxisLocation(99, AxisLocation.BOTTOM_OR_RIGHT);
    assertEquals(AxisLocation.BOTTOM_OR_RIGHT, plot.getDomainAxisLocation(99));
    plot.setRangeAxisLocation(99, AxisLocation.BOTTOM_OR_LEFT);
    assertEquals(AxisLocation.BOTTOM_OR_LEFT, plot.getRangeAxisLocation(99));
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Example 64 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testRangeMarkerIndices.

@Test
public void testRangeMarkerIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    // add a second dataset, plotted against a second axis
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset);
    NumberAxis yAxis2 = new NumberAxis("Y2");
    plot.setRangeAxis(1, yAxis2);
    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    plot.mapDatasetToRangeAxis(99, 1);
    ValueMarker yMarker1 = new ValueMarker(123);
    plot.addRangeMarker(99, yMarker1, Layer.FOREGROUND);
    assertTrue(plot.getRangeMarkers(99, Layer.FOREGROUND).contains(yMarker1));
}
Also used : LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Example 65 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testAxisRange.

/**
 * A test for a bug reported in the forum.
 */
@Test
public void testAxisRange() {
    DefaultCategoryDataset datasetA = new DefaultCategoryDataset();
    DefaultCategoryDataset datasetB = new DefaultCategoryDataset();
    datasetB.addValue(50.0, "R1", "C1");
    datasetB.addValue(80.0, "R1", "C1");
    CategoryPlot plot = new CategoryPlot(datasetA, new CategoryAxis(null), new NumberAxis(null), new LineAndShapeRenderer());
    plot.setDataset(1, datasetB);
    plot.setRenderer(1, new LineAndShapeRenderer());
    Range r = plot.getRangeAxis().getRange();
    assertEquals(84.0, r.getUpperBound(), 0.00001);
}
Also used : LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) Range(org.jfree.data.Range) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Aggregations

NumberAxis (org.jfree.chart.axis.NumberAxis)259 JFreeChart (org.jfree.chart.JFreeChart)146 Test (org.junit.Test)118 XYPlot (org.jfree.chart.plot.XYPlot)98 CategoryAxis (org.jfree.chart.axis.CategoryAxis)95 CategoryPlot (org.jfree.chart.plot.CategoryPlot)80 ValueAxis (org.jfree.chart.axis.ValueAxis)45 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)44 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)40 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)39 XYSeries (org.jfree.data.xy.XYSeries)38 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)37 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)30 XYDataset (org.jfree.data.xy.XYDataset)30 Color (java.awt.Color)28 DateAxis (org.jfree.chart.axis.DateAxis)27 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)27 BasicStroke (java.awt.BasicStroke)25 StandardXYItemRenderer (org.jfree.chart.renderer.xy.StandardXYItemRenderer)24 CategoryDataset (org.jfree.data.category.CategoryDataset)21