Search in sources :

Example 11 with XYURLGenerator

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

the class ChartFactory method createStackedXYAreaChart.

/**
 * Creates a stacked XY area plot.  The chart object returned by this
 * method uses an {@link XYPlot} instance as the plot, with a
 * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the
 * range axis, and a {@link StackedXYAreaRenderer2} as the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A stacked XY area chart.
 */
public static JFreeChart createStackedXYAreaChart(String title, String xAxisLabel, String yAxisLabel, TableXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {
    ParamChecks.nullNotPermitted(orientation, "orientation");
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }
    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(toolTipGenerator, urlGenerator);
    renderer.setOutline(true);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    // forces recalculation of the axis range
    plot.setRangeAxis(yAxis);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) StackedXYAreaRenderer2(org.jfree.chart.renderer.xy.StackedXYAreaRenderer2) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) XYURLGenerator(org.jfree.chart.urls.XYURLGenerator) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator)

Example 12 with XYURLGenerator

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

the class ChartFactory method createTimeSeriesChart.

/**
 * Creates and returns a time series chart.  A time series chart is an
 * {@link XYPlot} with a {@link DateAxis} for the x-axis and a
 * {@link NumberAxis} for the y-axis.  The default renderer is an
 * {@link XYLineAndShapeRenderer}.
 * <P>
 * A convenient dataset to use with this chart is a
 * {@link org.jfree.data.time.TimeSeriesCollection}.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A time series chart.
 */
public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset, boolean legend, boolean tooltips, boolean urls) {
    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    // reduce the default margins
    timeAxis.setLowerMargin(0.02);
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    // override default
    valueAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    }
    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    plot.setRenderer(renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) XYURLGenerator(org.jfree.chart.urls.XYURLGenerator) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator)

Example 13 with XYURLGenerator

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

the class ChartFactory method createXYAreaChart.

/**
 * Creates an area chart using an {@link XYDataset}.
 * <P>
 * The chart object returned by this method uses an {@link XYPlot} instance
 * as the plot, with a {@link NumberAxis} for the domain axis, a
 * {@link NumberAxis} as the range axis, and a {@link XYAreaRenderer} as
 * the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return An XY area chart.
 */
public static JFreeChart createXYAreaChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {
    ParamChecks.nullNotPermitted(orientation, "orientation");
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setOrientation(orientation);
    plot.setForegroundAlpha(0.5f);
    XYToolTipGenerator tipGenerator = null;
    if (tooltips) {
        tipGenerator = new StandardXYToolTipGenerator();
    }
    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    plot.setRenderer(new XYAreaRenderer(XYAreaRenderer.AREA, tipGenerator, urlGenerator));
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : XYAreaRenderer(org.jfree.chart.renderer.xy.XYAreaRenderer) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) XYURLGenerator(org.jfree.chart.urls.XYURLGenerator) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator)

Example 14 with XYURLGenerator

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

the class ChartFactory method createXYStepAreaChart.

/**
 * Creates a filled stepped XY plot with default settings.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A chart.
 */
public static JFreeChart createXYStepAreaChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {
    ParamChecks.nullNotPermitted(orientation, "orientation");
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }
    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYItemRenderer renderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator, urlGenerator);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) XYURLGenerator(org.jfree.chart.urls.XYURLGenerator) XYStepAreaRenderer(org.jfree.chart.renderer.xy.XYStepAreaRenderer) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer)

Example 15 with XYURLGenerator

use of org.jfree.chart.urls.XYURLGenerator in project seng438-a3-R41Ryan by seng438-winter-2022.

the class XYDifferenceRenderer method drawItemPass1.

/**
 * Draws the visual representation of a single data item, second pass.  In
 * the second pass, the renderer draws the lines and shapes for the
 * individual points in the two series.
 *
 * @param x_graphics  the graphics device.
 * @param x_dataArea  the area within which the data is being drawn.
 * @param x_info  collects information about the drawing.
 * @param x_plot  the plot (can be used to obtain standard color
 *         information etc).
 * @param x_domainAxis  the domain (horizontal) axis.
 * @param x_rangeAxis  the range (vertical) axis.
 * @param x_dataset  the dataset.
 * @param x_series  the series index (zero-based).
 * @param x_item  the item index (zero-based).
 * @param x_crosshairState  crosshair information for the plot
 *                          (<code>null</code> permitted).
 */
protected void drawItemPass1(Graphics2D x_graphics, Rectangle2D x_dataArea, PlotRenderingInfo x_info, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, XYDataset x_dataset, int x_series, int x_item, CrosshairState x_crosshairState) {
    Shape l_entityArea = null;
    EntityCollection l_entities = null;
    if (null != x_info) {
        l_entities = x_info.getOwner().getEntityCollection();
    }
    Paint l_seriesPaint = getItemPaint(x_series, x_item);
    Stroke l_seriesStroke = getItemStroke(x_series, x_item);
    x_graphics.setPaint(l_seriesPaint);
    x_graphics.setStroke(l_seriesStroke);
    PlotOrientation l_orientation = x_plot.getOrientation();
    RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
    RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
    double l_x0 = x_dataset.getXValue(x_series, x_item);
    double l_y0 = x_dataset.getYValue(x_series, x_item);
    double l_x1 = x_domainAxis.valueToJava2D(l_x0, x_dataArea, l_domainAxisLocation);
    double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea, l_rangeAxisLocation);
    if (getShapesVisible()) {
        Shape l_shape = getItemShape(x_series, x_item);
        if (l_orientation == PlotOrientation.HORIZONTAL) {
            l_shape = ShapeUtilities.createTranslatedShape(l_shape, l_y1, l_x1);
        } else {
            l_shape = ShapeUtilities.createTranslatedShape(l_shape, l_x1, l_y1);
        }
        if (l_shape.intersects(x_dataArea)) {
            x_graphics.setPaint(getItemPaint(x_series, x_item));
            x_graphics.fill(l_shape);
        }
        l_entityArea = l_shape;
    }
    // add an entity for the item...
    if (null != l_entities) {
        if (null == l_entityArea) {
            l_entityArea = new Rectangle2D.Double((l_x1 - 2), (l_y1 - 2), 4, 4);
        }
        String l_tip = null;
        XYToolTipGenerator l_tipGenerator = getToolTipGenerator(x_series, x_item);
        if (null != l_tipGenerator) {
            l_tip = l_tipGenerator.generateToolTip(x_dataset, x_series, x_item);
        }
        String l_url = null;
        XYURLGenerator l_urlGenerator = getURLGenerator();
        if (null != l_urlGenerator) {
            l_url = l_urlGenerator.generateURL(x_dataset, x_series, x_item);
        }
        XYItemEntity l_entity = new XYItemEntity(l_entityArea, x_dataset, x_series, x_item, l_tip, l_url);
        l_entities.add(l_entity);
    }
    // draw the item label if there is one...
    if (isItemLabelVisible(x_series, x_item)) {
        drawItemLabel(x_graphics, l_orientation, x_dataset, x_series, x_item, l_x1, l_y1, (l_y1 < 0.0));
    }
    int l_domainAxisIndex = x_plot.getDomainAxisIndex(x_domainAxis);
    int l_rangeAxisIndex = x_plot.getRangeAxisIndex(x_rangeAxis);
    updateCrosshairValues(x_crosshairState, l_x0, l_y0, l_domainAxisIndex, l_rangeAxisIndex, l_x1, l_y1, l_orientation);
    if (0 == x_item) {
        return;
    }
    double l_x2 = x_domainAxis.valueToJava2D(x_dataset.getXValue(x_series, (x_item - 1)), x_dataArea, l_domainAxisLocation);
    double l_y2 = x_rangeAxis.valueToJava2D(x_dataset.getYValue(x_series, (x_item - 1)), x_dataArea, l_rangeAxisLocation);
    Line2D l_line = null;
    if (PlotOrientation.HORIZONTAL == l_orientation) {
        l_line = new Line2D.Double(l_y1, l_x1, l_y2, l_x2);
    } else if (PlotOrientation.VERTICAL == l_orientation) {
        l_line = new Line2D.Double(l_x1, l_y1, l_x2, l_y2);
    }
    if ((null != l_line) && l_line.intersects(x_dataArea)) {
        x_graphics.setPaint(getItemPaint(x_series, x_item));
        x_graphics.setStroke(getItemStroke(x_series, x_item));
        x_graphics.draw(l_line);
    }
}
Also used : Stroke(java.awt.Stroke) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) XYURLGenerator(org.jfree.chart.urls.XYURLGenerator) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) XYItemEntity(org.jfree.chart.entity.XYItemEntity) EntityCollection(org.jfree.chart.entity.EntityCollection) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) RectangleEdge(org.jfree.ui.RectangleEdge)

Aggregations

XYToolTipGenerator (org.jfree.chart.labels.XYToolTipGenerator)23 XYURLGenerator (org.jfree.chart.urls.XYURLGenerator)23 NumberAxis (org.jfree.chart.axis.NumberAxis)18 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)18 XYPlot (org.jfree.chart.plot.XYPlot)18 StandardXYURLGenerator (org.jfree.chart.urls.StandardXYURLGenerator)18 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)9 DateAxis (org.jfree.chart.axis.DateAxis)6 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)6 Shape (java.awt.Shape)5 XYItemEntity (org.jfree.chart.entity.XYItemEntity)5 Paint (java.awt.Paint)4 Stroke (java.awt.Stroke)4 Line2D (java.awt.geom.Line2D)4 Rectangle2D (java.awt.geom.Rectangle2D)4 EntityCollection (org.jfree.chart.entity.EntityCollection)4 PlotOrientation (org.jfree.chart.plot.PlotOrientation)4 ValueAxis (org.jfree.chart.axis.ValueAxis)3 StackedXYAreaRenderer2 (org.jfree.chart.renderer.xy.StackedXYAreaRenderer2)3 XYAreaRenderer (org.jfree.chart.renderer.xy.XYAreaRenderer)3