Example usage for org.jfree.chart.plot CategoryPlot getDataset

List of usage examples for org.jfree.chart.plot CategoryPlot getDataset

Introduction

In this page you can find the example usage for org.jfree.chart.plot CategoryPlot getDataset.

Prototype

public CategoryDataset getDataset() 

Source Link

Document

Returns the primary dataset for the plot.

Usage

From source file:org.gaixie.micrite.jfreechart.style.BarStyle.java

/**
 * ???/*from w w w . j  a  va 2  s  .co m*/
 * @param chart JFreeChart
 */
public static void styleOne(JFreeChart chart) {
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    CategoryDataset dca = categoryplot.getDataset();
    //?
    chart.setBackgroundPaint(null);
    if (dca != null) {
        BarRenderer categoryitemrenderer = (BarRenderer) categoryplot.getRenderer();
        // ?
        categoryitemrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        //            categoryitemrenderer.setBaseItemLabelFont(
        //                    new Font("", Font.PLAIN, 15));
        categoryitemrenderer.setBaseItemLabelsVisible(true);
        //tooltip
        categoryplot.getRenderer()
                .setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{0}={2}", new DecimalFormat()));
        //?
        for (int i = 0; i < dca.getRowCount(); i++) {
            int colorIdx = i % colors.length;
            categoryitemrenderer.setSeriesPaint(i, colors[colorIdx]);
        }
    } else {
        //?
        categoryplot.setNoDataMessage("NO DATA");
    }
}

From source file:org.eobjects.datacleaner.util.ChartUtils.java

public static void applyStyles(JFreeChart chart) {
    TextTitle title = chart.getTitle();//from w  ww  .ja  va2 s.com
    if (title != null) {
        title.setFont(WidgetUtils.FONT_HEADER1);
        title.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    }

    for (int i = 0; i < chart.getSubtitleCount(); i++) {
        Title subtitle = chart.getSubtitle(i);
        if (subtitle instanceof TextTitle) {
            ((TextTitle) subtitle).setFont(WidgetUtils.FONT_NORMAL);
        }
    }

    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setItemFont(WidgetUtils.FONT_SMALL);
    }

    // transparent background
    chart.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    chart.setBorderVisible(false);

    final Plot plot = chart.getPlot();
    plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0d, 0d, 0d, 0d));
    plot.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlinePaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlineVisible(true);

    if (plot instanceof PiePlot) {
        // tweaks for pie charts
        final PiePlot piePlot = (PiePlot) plot;
        piePlot.setBaseSectionOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setBaseSectionOutlineStroke(normalStroke);
        piePlot.setLabelFont(WidgetUtils.FONT_SMALL);
        piePlot.setLabelBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHT);
        piePlot.setLabelOutlineStroke(normalStroke);
        piePlot.setLabelPaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setSectionOutlinesVisible(false);
        piePlot.setLabelLinkStyle(PieLabelLinkStyle.QUAD_CURVE);
    } else if (plot instanceof CategoryPlot) {
        // tweaks for bar charts
        final CategoryPlot categoryPlot = (CategoryPlot) plot;

        int columnCount = categoryPlot.getDataset().getColumnCount();
        if (columnCount > 1) {
            categoryPlot.setDomainGridlinesVisible(true);
        } else {
            categoryPlot.setDomainGridlinesVisible(false);
        }
        categoryPlot.setDomainGridlinePaint(WidgetUtils.BG_COLOR_DARK);
        categoryPlot.setDomainGridlinePosition(CategoryAnchor.END);

        categoryPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.setDrawingSupplier(new DCDrawingSupplier());

        final CategoryItemRenderer renderer = categoryPlot.getRenderer();
        renderer.setBaseOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        renderer.setBaseOutlineStroke(wideStroke);

        if (renderer instanceof BarRenderer) {
            BarRenderer barRenderer = (BarRenderer) renderer;
            barRenderer.setShadowPaint(WidgetUtils.BG_COLOR_BRIGHT);
            barRenderer.setBarPainter(new StandardBarPainter());
        }

    } else if (plot instanceof XYPlot) {
        // tweaks for line charts
        final XYPlot xyPlot = (XYPlot) plot;

        xyPlot.setDrawingSupplier(new DCDrawingSupplier());

        xyPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);

        final XYItemRenderer renderer = xyPlot.getRenderer();
        final int seriesCount = xyPlot.getSeriesCount();
        for (int i = 0; i < seriesCount; i++) {
            renderer.setSeriesStroke(i, wideStroke);
        }
    }
}

From source file:org.datacleaner.util.ChartUtils.java

public static void applyStyles(JFreeChart chart) {
    TextTitle title = chart.getTitle();/*w  ww .  j  av a2 s  .  c  om*/
    if (title != null) {
        title.setFont(WidgetUtils.FONT_HEADER1);
        title.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    }

    for (int i = 0; i < chart.getSubtitleCount(); i++) {
        Title subtitle = chart.getSubtitle(i);
        if (subtitle instanceof TextTitle) {
            ((TextTitle) subtitle).setFont(WidgetUtils.FONT_NORMAL);
        }
    }

    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setItemFont(WidgetUtils.FONT_SMALL);
    }

    // transparent background
    chart.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    chart.setBorderVisible(false);

    final Plot plot = chart.getPlot();
    plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0d, 0d, 0d, 0d));
    plot.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlinePaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlineVisible(true);

    if (plot instanceof PiePlot) {
        // tweaks for pie charts
        final PiePlot piePlot = (PiePlot) plot;
        piePlot.setBaseSectionOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setBaseSectionOutlineStroke(STROKE_NORMAL);
        piePlot.setLabelFont(WidgetUtils.FONT_SMALL);
        piePlot.setLabelBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHT);
        piePlot.setLabelOutlineStroke(STROKE_NORMAL);
        piePlot.setLabelPaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setSectionOutlinesVisible(false);
        piePlot.setLabelLinkStyle(PieLabelLinkStyle.QUAD_CURVE);
        piePlot.setDrawingSupplier(new DCDrawingSupplier());

    } else if (plot instanceof CategoryPlot) {
        // tweaks for bar charts
        final CategoryPlot categoryPlot = (CategoryPlot) plot;

        int columnCount = categoryPlot.getDataset().getColumnCount();
        if (columnCount > 1) {
            categoryPlot.setDomainGridlinesVisible(true);
        } else {
            categoryPlot.setDomainGridlinesVisible(false);
        }
        categoryPlot.setDomainGridlinePaint(WidgetUtils.BG_COLOR_DARK);
        categoryPlot.setDomainGridlinePosition(CategoryAnchor.END);

        categoryPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.setDrawingSupplier(new DCDrawingSupplier());

        final CategoryItemRenderer renderer = categoryPlot.getRenderer();
        renderer.setBaseOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        renderer.setBaseOutlineStroke(STROKE_WIDE);

        if (renderer instanceof BarRenderer) {
            BarRenderer barRenderer = (BarRenderer) renderer;
            barRenderer.setShadowPaint(WidgetUtils.BG_COLOR_BRIGHT);
            barRenderer.setBarPainter(new StandardBarPainter());
        }

    } else if (plot instanceof XYPlot) {
        // tweaks for line charts
        final XYPlot xyPlot = (XYPlot) plot;

        xyPlot.setDrawingSupplier(new DCDrawingSupplier());

        xyPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);

        final XYItemRenderer renderer = xyPlot.getRenderer();
        final int seriesCount = xyPlot.getSeriesCount();
        for (int i = 0; i < seriesCount; i++) {
            renderer.setSeriesStroke(i, STROKE_WIDE);
        }
    }
}

From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java

/**
 *
 * @param chartPanel/*  w  w w  .j a  va 2  s.co m*/
 * @param category
 * @param y
 * @return
 */
public static AffineTransform getModelToViewTransformCategory(ChartPanel chartPanel, int category, double y) {
    double zoomX = chartPanel.getScaleX();
    double zoomY = chartPanel.getScaleY();
    Insets insets = chartPanel.getInsets();
    AffineTransform at = getTranslateInstance(insets.left, insets.top);
    at.concatenate(getScaleInstance(zoomX, zoomY));
    Plot plot = chartPanel.getChart().getPlot();
    if (plot instanceof CategoryPlot) {
        CategoryPlot xyp = (CategoryPlot) plot;
        CategoryDataset cds = xyp.getDataset();
        RectangleEdge xAxisLocation = xyp.getDomainAxisEdge();
        RectangleEdge yAxisLocation = xyp.getRangeAxisEdge();
        PlotOrientation orientation = xyp.getOrientation();
        Comparable<?> categoryKey = cds.getColumnKey(category);
        Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
        double transX = xyp.getDomainAxis().getCategoryMiddle(categoryKey, cds.getColumnKeys(), dataArea,
                xAxisLocation);
        double transY = xyp.getRangeAxis().valueToJava2D(y, dataArea, yAxisLocation);
        if (orientation == PlotOrientation.HORIZONTAL) {
            double tmp = transX;
            transX = transY;
            transY = tmp;
        }
        at.concatenate(getTranslateInstance(transX, transY));
        return at;
    }
    throw new IllegalArgumentException("Unsupported plot type: " + plot.getClass());
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java

public static JFreeChart createChartWithCategoryDataSet(ChartData chartData) {
    JFreeChart chart = null;// w  w w  .j a  v  a  2  s.  c  om
    PlotOrientation plotOrientation = ChartUtils.getPlotOrientation(chartData.getOrientation());

    CategoryDataset dataset = (CategoryDataset) chartData.getDatasource();
    String type = chartData.getType();
    String xAxis = chartData.getXlabel();
    String yAxis = chartData.getYlabel();
    boolean is3d = chartData.isChart3d();
    boolean legend = chartData.isLegend();

    if (type.equalsIgnoreCase("bar")) {
        if (is3d == true) {
            chart = ChartFactory.createBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        } else {
            chart = ChartFactory.createBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        }
        setBarOutline(chart, chartData);
    } else if (type.equalsIgnoreCase("stackedbar")) {
        if (is3d == true) {
            chart = ChartFactory.createStackedBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend,
                    true, false);
        } else {
            chart = ChartFactory.createStackedBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        }
        setBarOutline(chart, chartData);
    } else if (type.equalsIgnoreCase("line")) {
        if (is3d == true)
            chart = ChartFactory.createLineChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        else
            chart = ChartFactory.createLineChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
    } else if (type.equalsIgnoreCase("area")) {
        chart = ChartFactory.createAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("stackedarea")) {
        chart = ChartFactory.createStackedAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                false);
    } else if (type.equalsIgnoreCase("waterfall")) {
        chart = ChartFactory.createWaterfallChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                false);
    } else if (type.equalsIgnoreCase("gantt")) {
        chart = ChartFactory.createGanttChart("", xAxis, yAxis, (IntervalCategoryDataset) dataset, legend, true,
                false);
    }

    CategoryPlot plot = (CategoryPlot) chart.getCategoryPlot();
    plot.setDomainGridlinesVisible(chartData.isDomainGridLines());
    plot.setRangeGridlinesVisible(chartData.isRangeGridLines());
    if (chartData.getGenerateMap() != null)
        plot.getRenderer().setBaseItemURLGenerator(new StandardCategoryURLGenerator(""));

    int seriesCount = plot.getDataset().getColumnCount();
    if (chartData.getLineStokeWidth() > 0) {
        for (int index = 0; index <= seriesCount; index++)
            plot.getRenderer().setSeriesStroke(index, new BasicStroke(chartData.getLineStokeWidth()));
    }

    setCategorySeriesColors(chart, chartData);

    setCategoryExtensions(chart, chartData);

    return chart;
}

From source file:org.sonar.plugins.scmstats.charts.StackedBarChart3DTest.java

@Test
public void testGetPlot() {
    Map<String, String> params = new HashMap<String, String>();
    params.put("v", "author1=1. 2. 3;author2=4. 5. 6;author3=7. 8. 9");
    ChartParameters chartParams = new ChartParameters(params);

    CategoryPlot result = (CategoryPlot) chart.getPlot(chartParams);

    assertThat(result).isNotNull();//from  w w w.  j av a2  s  .  c  o  m
    assertThat(result.getDataset().getRowKeys()).contains("Adding", "Modifying", "Deleting");
    assertThat(result.getDataset().getColumnKeys()).contains("author1", "author2", "author3");
    assertThat(result.getDataset().getValue("Adding", "author1")).isEqualTo(1.0);
    assertThat(result.getDataset().getValue("Deleting", "author3")).isEqualTo(9.0);

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.Prd4981Test.java

public void testChartProcessing50_Hidden() throws Exception {
    final URL url = getClass().getResource("Prd-4981.prpt");
    assertNotNull(url);/*w ww .  j  a v a  2s .  com*/
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();
    final Resource directly = resourceManager.createDirectly(url, MasterReport.class);
    final MasterReport report = (MasterReport) directly.getResource();

    final LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 0);

    final RenderNode[] elementsByElementType = MatchFactory.findElementsByNodeType(logicalPageBox,
            LayoutNodeTypes.TYPE_BOX_CONTENT);

    Assert.assertTrue(elementsByElementType.length > 0);

    for (final RenderNode renderNode : elementsByElementType) {
        final RenderableReplacedContentBox c = (RenderableReplacedContentBox) renderNode;
        final DrawableWrapper rawObject = (DrawableWrapper) c.getContent().getRawObject();
        final JFreeChartReportDrawable backend = (JFreeChartReportDrawable) rawObject.getBackend();
        final JFreeChart chart = backend.getChart();
        final CategoryPlot p = (CategoryPlot) chart.getPlot();
        final CategoryDataset dataset = p.getDataset();
        Assert.assertNotNull(dataset);
        DebugLog.log(rawObject);
    }
}

From source file:ca.sqlpower.wabit.swingui.chart.effect.BarChartAnimatorFactory.java

public boolean canAnimate(JFreeChart chart) {
    if (!(chart.getPlot() instanceof CategoryPlot)) {
        return false;
    }/* w  w w .  j a v a2 s . c  o m*/
    CategoryPlot cplot = chart.getCategoryPlot();
    if (cplot.getDatasetCount() != 1) {
        return false;
    }
    if (!(cplot.getDataset() instanceof DefaultCategoryDataset)) {
        return false;
    }
    return true;
}

From source file:org.talend.dataprofiler.chart.util.HideSeriesChartDialog.java

private Composite createUtilityControl(Composite parent) {
    Composite comp = new Composite(parent, SWT.BORDER);
    comp.setLayout(new RowLayout());
    comp.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));

    if (isCountAvgNull) {
        XYDataset dataset = chart.getXYPlot().getDataset();
        int count = dataset.getSeriesCount();

        for (int i = 0; i < count; i++) {

            Button checkBtn = new Button(comp, SWT.CHECK);
            checkBtn.setText(dataset.getSeriesKey(i).toString());
            checkBtn.setSelection(true);
            checkBtn.addSelectionListener(listener);
            checkBtn.setData(SERIES_KEY_ID, i);
        }//w w w  .j a  va  2s .  com
    }

    if (isMinMaxDate) {
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryDataset dataset = plot.getDataset();
        int count = dataset.getRowCount();

        for (int i = 0; i < count; i++) {

            Button checkBtn = new Button(comp, SWT.CHECK);
            checkBtn.setText(dataset.getRowKey(i).toString());
            checkBtn.setSelection(true);
            checkBtn.addSelectionListener(listener);
            checkBtn.setData(SERIES_KEY_ID, i);
        }
    }

    return comp;
}

From source file:com.choicemaker.cm.modelmaker.gui.utils.HistoChartPanel.java

protected void setContextMenu() {
    CategoryPlot categoryPlot = (CategoryPlot) getChart().getPlot();
    HistoCategoryDataset data = (HistoCategoryDataset) categoryPlot.getDataset();
    if (data.hasData()) {
        CategoryAxis axis = categoryPlot.getDomainAxis();

        //axis.set
        Rectangle2D plotArea = getScreenDataArea();
        final RectangleEdge edge = null;
        int cat = 0;
        int len = data.getColumnCount();
        for (int i = 0; i < len; ++i) {
            if (popupX >= axis.getCategoryStart(i, len, plotArea, edge)
                    && popupX <= axis.getCategoryEnd(i, len, plotArea, edge)) {
                cat = i;//from   ww w . j a v a2s .co m
                break;
            }
        }
        float step = 1f / len;
        rangeFrom = cat * step;
        rangeTo = rangeFrom + step;
        select.setText("Select range " + data.getColumnKey(cat));
    }
    select.setEnabled(data.hasData());
}