Search in sources :

Example 1 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project qpid-broker-j by apache.

the class BaseChartBuilderTest method testBuildChart.

public void testBuildChart() {
    BaseChartBuilder chartBuilder = new ChartBuilder(_seriesBuilder, _strokeAndPaintApplier, _datasetHolder) {

        @Override
        protected JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) {
            assertEquals(CHART_TITLE, title);
            assertEquals(X_TITLE, xAxisTitle);
            assertEquals(Y_TITLE, yAxisTitle);
            return _jFreeChart;
        }
    };
    JFreeChart chart = chartBuilder.buildChart(_chartingDefinition);
    assertEquals(BaseChartBuilder.BLUE_GRADIENT, chart.getBackgroundPaint());
    assertEquals("The *second* subtitle of the generated chart should have the text from the chart definition", CHART_SUB_TITLE, ((TextTitle) chart.getSubtitle(1)).getText());
    verify(_seriesPainter).applySeriesAppearance(_jFreeChart, _seriesDefinitions, _strokeAndPaintApplier);
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Dataset(org.jfree.data.general.Dataset) JFreeChart(org.jfree.chart.JFreeChart)

Example 2 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation 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 3 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project cytoscape-impl by cytoscape.

the class HeatMapLayer method createChart.

@Override
protected JFreeChart createChart(final XYZDataset dataset) {
    final PlotOrientation plotOrientation = orientation == Orientation.HORIZONTAL ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL;
    final SymbolAxis xAxis = new SymbolAxis(null, xLabels);
    xAxis.setVisible(showDomainAxis);
    xAxis.setAxisLineVisible(false);
    xAxis.setTickMarksVisible(false);
    xAxis.setTickLabelFont(xAxis.getLabelFont().deriveFont(axisFontSize));
    xAxis.setTickLabelPaint(axisColor);
    xAxis.setVerticalTickLabels(domainLabelPosition != LabelPosition.STANDARD);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    final SymbolAxis yAxis = new SymbolAxis(null, yLabels);
    yAxis.setVisible(showRangeAxis);
    yAxis.setAxisLineVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setTickLabelFont(yAxis.getLabelFont().deriveFont(axisFontSize));
    yAxis.setTickLabelPaint(axisColor);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setInverted(true);
    final XYBlockRenderer renderer = new XYBlockRenderer();
    if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
        final int colorsSize = colors != null ? colors.size() : 0;
        Color upperColor = colorsSize > 0 ? colors.get(0) : Color.BLUE;
        Color zeroColor = colorsSize > 1 ? colors.get(1) : Color.WHITE;
        Color lowerColor = colorsSize > 2 ? colors.get(2) : Color.RED;
        Color nanColor = colorsSize > 3 ? colors.get(3) : Color.GRAY;
        final ColorScale scale = new ColorScale(range.get(0), range.get(1), lowerColor, zeroColor, upperColor, nanColor);
        renderer.setPaintScale(scale);
    }
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setDomainAxis(xAxis);
    plot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setBackgroundPaint(TRANSPARENT_COLOR);
    plot.setInsets(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    plot.setOrientation(plotOrientation);
    final JFreeChart chart = new JFreeChart(null, plot);
    chart.removeLegend();
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(TRANSPARENT_COLOR);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    return chart;
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) XYPlot(org.jfree.chart.plot.XYPlot) Color(java.awt.Color) XYBlockRenderer(org.jfree.chart.renderer.xy.XYBlockRenderer) ColorScale(org.cytoscape.ding.internal.charts.util.ColorScale) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart) SymbolAxis(org.jfree.chart.axis.SymbolAxis)

Example 4 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project tdq-studio-se by Talend.

the class HideSeriesGanttRenderer method drawTask.

/**
 * Draws a single task.
 *
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the data plot area.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the data.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 */
protected void drawTask(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) {
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
    // Y0
    Number value0 = dataset.getEndValue(row, column);
    if (value0 == null) {
        return;
    }
    double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);
    // Y1
    Number value1 = dataset.getStartValue(row, column);
    if (value1 == null) {
        return;
    }
    double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);
    if (java2dValue1 < java2dValue0) {
        double temp = java2dValue1;
        java2dValue1 = java2dValue0;
        java2dValue0 = temp;
        Number tempNum = value1;
        value1 = value0;
        value0 = tempNum;
    }
    // count the number of non-null values
    int totalBars = countNonNullValues(dataset, column);
    if (totalBars == 0) {
        return;
    }
    // count non-null values up to but not including the current value
    int priorBars = countPriorNonNullValues(dataset, column, row);
    // double rectStart = calculateBarW0(plot, orientation, dataArea,
    // domainAxis, state, row, column);
    // double rectBreadth = state.getBarWidth();
    double rectBreadth = (domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge())) / totalBars;
    double rectStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) + rectBreadth * priorBars;
    double rectLength = Math.abs(java2dValue1 - java2dValue0);
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth);
    } else if (orientation == PlotOrientation.VERTICAL) {
        bar = new Rectangle2D.Double(rectStart, java2dValue1, rectBreadth, rectLength);
    }
    Rectangle2D completeBar = null;
    Rectangle2D incompleteBar = null;
    Number percent = dataset.getPercentComplete(row, column);
    double start = getStartPercent();
    double end = getEndPercent();
    if (percent != null) {
        double p = percent.doubleValue();
        if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            completeBar = new Rectangle2D.Double(java2dValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start));
            incompleteBar = new Rectangle2D.Double(java2dValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start));
        } else if (plot.getOrientation() == PlotOrientation.VERTICAL) {
            completeBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1 + rectLength * (1 - p), rectBreadth * (end - start), rectLength * p);
            incompleteBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1, rectBreadth * (end - start), rectLength * (1 - p));
        }
    }
    Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (completeBar != null) {
        g2.setPaint(getCompletePaint());
        g2.fill(completeBar);
    }
    if (incompleteBar != null) {
        g2.setPaint(getIncompletePaint());
        g2.fill(incompleteBar);
    }
    // draw the outline...
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, false);
    }
    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, row, dataset.getColumnKey(column), column);
            entities.add(entity);
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) Rectangle2D(java.awt.geom.Rectangle2D) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) Paint(java.awt.Paint) EntityCollection(org.jfree.chart.entity.EntityCollection) CategoryToolTipGenerator(org.jfree.chart.labels.CategoryToolTipGenerator) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 5 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project Openfire by igniterealtime.

the class GraphEngine method createTimeAreaChart.

/**
     * Generates a generic Time Area Chart.
     *
     * @param title      the title of the Chart.
     * @param valueLabel the Y Axis label.
     * @param data       the data to populate with.
     * @return the generated Chart.
     */
private JFreeChart createTimeAreaChart(String title, String color, String valueLabel, XYDataset data) {
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    DateAxis xAxis = generateTimeAxis();
    NumberAxis yAxis = new NumberAxis(valueLabel);
    NumberFormat formatter = NumberFormat.getNumberInstance(JiveGlobals.getLocale());
    formatter.setMaximumFractionDigits(2);
    formatter.setMinimumFractionDigits(0);
    yAxis.setNumberFormatOverride(formatter);
    XYAreaRenderer renderer = new XYAreaRenderer(XYAreaRenderer.AREA);
    renderer.setOutline(true);
    return createChart(title, data, xAxis, yAxis, orientation, renderer, GraphDefinition.getDefinition(color));
}
Also used : XYAreaRenderer(org.jfree.chart.renderer.xy.XYAreaRenderer) PlotOrientation(org.jfree.chart.plot.PlotOrientation) NumberFormat(java.text.NumberFormat)

Aggregations

PlotOrientation (org.jfree.chart.plot.PlotOrientation)15 JFreeChart (org.jfree.chart.JFreeChart)9 NumberAxis (org.jfree.chart.axis.NumberAxis)6 Paint (java.awt.Paint)5 ValueAxis (org.jfree.chart.axis.ValueAxis)5 RectangleEdge (org.jfree.ui.RectangleEdge)5 CategoryAxis (org.jfree.chart.axis.CategoryAxis)4 EntityCollection (org.jfree.chart.entity.EntityCollection)4 CategoryPlot (org.jfree.chart.plot.CategoryPlot)4 BasicStroke (java.awt.BasicStroke)3 ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)3 XYPlot (org.jfree.chart.plot.XYPlot)3 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)3 RectangleInsets (org.jfree.ui.RectangleInsets)3 Color (java.awt.Color)2 GradientPaint (java.awt.GradientPaint)2 Stroke (java.awt.Stroke)2 Ellipse2D (java.awt.geom.Ellipse2D)2 Rectangle2D (java.awt.geom.Rectangle2D)2 NumberFormat (java.text.NumberFormat)2