Example usage for org.jfree.chart JFreeChart getCategoryPlot

List of usage examples for org.jfree.chart JFreeChart getCategoryPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getCategoryPlot.

Prototype

public CategoryPlot getCategoryPlot() 

Source Link

Document

Returns the plot cast as a CategoryPlot .

Usage

From source file:WeeklyReport.Sections.Bookings.java

private JFreeChart bookingsByPODChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Map<Double, Map<String, String>> map = new CargoQuoteType().bookingsByPOD();
    map.entrySet().stream().forEach((mapEntry) -> {
        Map<String, String> m1 = mapEntry.getValue();
        m1.entrySet().stream().forEach((pair) -> {
            dataset.setValue(mapEntry.getKey(), pair.getKey(), pair.getValue());
        });//from  w  w w .ja va  2 s . c  o  m
    });
    JFreeChart barChart = ChartFactory.createBarChart3D("Bookings by POD", "Company", "Cubic Meters", dataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    barChart.setBackgroundPaint(Color.WHITE);
    CategoryPlot categoryPlot = barChart.getCategoryPlot();
    CategoryAxis domainAxis = categoryPlot.getDomainAxis();
    BarRenderer br = (BarRenderer) categoryPlot.getRenderer();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    categoryPlot.setBackgroundPaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(Color.BLACK);
    return barChart;
}

From source file:GUI.TelaPrincipal.java

private void botaoConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoConsultarActionPerformed
    DefaultCategoryDataset barChartData = new DefaultCategoryDataset();
    barChartData.setValue(20000, "Contribution", "JANUARY");
    barChartData.setValue(15000, "Contribution", "FEBRUARY");
    barChartData.setValue(30000, "Contribution", "MARCH");

    JFreeChart barChart = ChartFactory.createBarChart("Church", "Monthly", "Contribution", barChartData,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot barchrt = barChart.getCategoryPlot();
    barchrt.setRangeGridlinePaint(Color.PINK);
    barchrt.setBackgroundPaint(Color.WHITE);

    ChartFrame frame = new ChartFrame("Lala", barChart);
    frame.setVisible(true);// ww  w. ja  v a 2s.  c om
    frame.setSize(800, 500);

}

From source file:org.neo4j.bench.chart.JFreeBarChart.java

@Override
protected JFreeChart createChart(AbstractDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart("Performance chart", "Bench case", "Time(s)",
            (DefaultCategoryDataset) dataset, PlotOrientation.VERTICAL, true, true, false);

    rotateCategoryAxis(chart, Math.PI / 4.0);
    CategoryPlot plot = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setItemLabelGenerator(new CategoryItemLabelGenerator() {
        public String generateColumnLabel(CategoryDataset dataset, int column) {
            return "col" + column;
        }/*from   w w  w  . j  a v a 2  s.co  m*/

        public String generateLabel(CategoryDataset dataset, int row, int column) {
            return "" + dataset.getValue(row, column).intValue();
        }

        public String generateRowLabel(CategoryDataset dataset, int row) {
            return "row" + row;
        }
    });
    renderer.setBaseItemLabelPaint(Color.black);
    renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE12,
            TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0));
    renderer.setItemLabelsVisible(true);

    return chart;
}

From source file:org.pentaho.chart.plugin.jfreechart.chart.line.JFreeLineChartGenerator.java

protected JFreeChart doCreateChart(final ChartDocumentContext chartDocContext, final ChartTableModel data) {
    final ChartDocument chartDocument = chartDocContext.getChartDocument();
    final String title = getTitle(chartDocument);
    final String valueCategoryLabel = getValueCategoryLabel(chartDocument);
    final String valueAxisLabel = getValueAxisLabel(chartDocument);
    final PlotOrientation orientation = getPlotOrientation(chartDocument);
    final boolean legend = getShowLegend(chartDocument);
    final boolean toolTips = getShowToolTips(chartDocument);

    final DefaultCategoryDataset categoryDataset = datasetGeneratorFactory
            .createDefaultCategoryDataset(chartDocContext, data);

    final JFreeChart chart = ChartFactory.createLineChart(title, valueCategoryLabel, valueAxisLabel,
            categoryDataset, orientation, legend, toolTips, toolTips);

    final CategoryPlot categoryPlot = chart.getCategoryPlot();
    final ChartElement[] seriesElements = chartDocument.getRootElement()
            .findChildrenByName(ChartElement.TAG_NAME_SERIES);
    if (categoryPlot != null && seriesElements != null) {
        setSeriesAttributes(seriesElements, data, categoryPlot);
    }//from w  ww  .  j a  v  a 2s.c  om

    return chart;
}

From source file:ch.opentrainingcenter.charts.bar.OTCCategoryChartViewerTest.java

@Test
public void updateRendererMonth() {
    final Color colorNow = new Color(1, 2, 3, OTCCategoryChartViewer.ALPHA);
    when(store.getString(PreferenceConstants.CHART_DISTANCE_COLOR)).thenReturn("1,2,3");

    final JFreeChart mockedChart = mock(JFreeChart.class);
    final CategoryPlot plot = mock(CategoryPlot.class);
    when(mockedChart.getCategoryPlot()).thenReturn(plot);
    viewer.setChart(mockedChart);/*from w w w.j a  v a 2s. c o  m*/

    // Execute
    viewer.updateRenderer(XAxisChart.MONTH, TrainingChart.DISTANZ, true);

    final BarRenderer renderer = viewer.getRenderer();

    assertNotNull(renderer);
    final Color past = (Color) renderer.getSeriesPaint(1);
    assertEquals(colorNow.brighter(), past);

    final Color now = (Color) renderer.getSeriesPaint(2);
    assertEquals(colorNow, now);

    final BarPainter barPainter = renderer.getBarPainter();

    assertTrue(barPainter instanceof OTCBarPainter);

    assertEquals(0.0, renderer.getItemMargin(), 0.001);

    verify(plot).setRenderer(renderer);
}

From source file:WeeklyReport.Sections.Bookings.java

private JFreeChart bookingsByTradelaneChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Map<Double, Map<String, String>> map = new CargoQuoteType().bookingsByTradeLane();
    map.entrySet().stream().forEach((mapEntry) -> {
        Map<String, String> m1 = mapEntry.getValue();
        m1.entrySet().stream().forEach((pair) -> {
            dataset.setValue(mapEntry.getKey(), pair.getKey(), pair.getValue());
        });/*from   w  w w . j  a v a  2  s.c o  m*/
    });
    JFreeChart barChart = ChartFactory.createBarChart3D("Bookings by Trade Lane", "Company", "Cubic Meters",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    barChart.setBackgroundPaint(Color.WHITE);
    CategoryPlot categoryPlot = barChart.getCategoryPlot();
    CategoryAxis domainAxis = categoryPlot.getDomainAxis();
    BarRenderer br = (BarRenderer) categoryPlot.getRenderer();
    if (map.values().stream().mapToInt((list) -> list.size()).count() > 2) {
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    }
    categoryPlot.setBackgroundPaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(Color.BLACK);
    return barChart;
}

From source file:parts.GraphicContent.java

public void setContent(JPanel panel) {
    String sprint[] = null;//from   ww  w .jav  a 2  s . c o  m
    int taskCount[] = null;
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    try {
        Statement st = scrum.SCRUM.conexao.createStatement();
        String sql = "select COUNT(*) from sprint";
        result = st.executeQuery(sql);
        result.next();
        sprint = new String[result.getInt(1)];
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        Statement st = scrum.SCRUM.conexao.createStatement();
        String sql = "select * from sprint";
        result = st.executeQuery(sql);
        int i = 0;
        while (result.next()) {
            sprint[i] = result.getString("alias");
            i++;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    int sprintIDs[] = new int[sprint.length];

    try {
        Statement st = scrum.SCRUM.conexao.createStatement();
        String sql = "select * from sprint";
        result = st.executeQuery(sql);
        int i = 0;
        while (result.next()) {
            sprintIDs[i] = result.getInt("idsprint");
            i++;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    for (int i = 0; i < sprint.length; i++) {
        try {
            Statement st = scrum.SCRUM.conexao.createStatement();
            String sql = "select COUNT(*) from sprint_tasks  where idsprint  = " + sprintIDs[i];
            result = st.executeQuery(sql);
            while (result.next()) {
                dataset.addValue(result.getInt(1), "Tarefas", sprint[i]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    JFreeChart chart = null;
    chart = ChartFactory.createBarChart("Quantidade de tarefas por Sprint", "Sprint", "Tarefas", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);

    ChartPanel cp = new ChartPanel(chart);
    cp.setBounds(0, 0, panel.getWidth(), panel.getHeight());
    panel.removeAll();
    cp.setVisible(true);
    panel.add(cp);
    panel.revalidate();
    panel.repaint();
}

From source file:org.pentaho.chart.plugin.jfreechart.chart.bar.JFreeWaterfallBarChartGenerator.java

protected JFreeChart doCreateChart(final ChartDocumentContext chartDocContext, final ChartTableModel data) {
    final ChartDocument chartDocument = chartDocContext.getChartDocument();
    final String title = getTitle(chartDocument);
    final String valueCategoryLabel = getValueCategoryLabel(chartDocument);
    final String valueAxisLabel = getValueAxisLabel(chartDocument);
    final PlotOrientation orientation = getPlotOrientation(chartDocument);
    final boolean legend = getShowLegend(chartDocument);
    final boolean toolTips = getShowToolTips(chartDocument);

    final DefaultCategoryDataset categoryDataset = datasetGeneratorFactory
            .createDefaultCategoryDataset(chartDocContext, data);

    final JFreeChart chart = ChartFactory.createWaterfallChart(title, valueCategoryLabel, valueAxisLabel,
            categoryDataset, orientation, legend, toolTips, toolTips);

    final CategoryPlot categoryPlot = chart.getCategoryPlot();
    final ChartElement plotElement = chartDocument.getRootElement()
            .findChildrenByName(ChartElement.TAG_NAME_PLOT)[0];
    setPlotAttributes(categoryPlot, plotElement);
    final ChartElement[] seriesElements = chartDocument.getRootElement()
            .findChildrenByName(ChartElement.TAG_NAME_SERIES);
    if (categoryPlot != null && seriesElements != null) {
        setSeriesAttributes(seriesElements, data, categoryPlot);
    }//w  w w.  j av  a 2s.  c  o  m

    return chart;
}

From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java

/**
 * Creates a JFreeChart based on the current query results produced by the
 * given chart./*from   w ww. j  a  v a2 s. c  o m*/
 * 
 * @param c
 *            The chart from which to produce a JFreeChart component. Must
 *            not be null.
 * @return A chart based on the data and settings in the given chart, or
 *         null if the given chart is not sufficiently configured (for
 *         example, if its type is not set) or it is currently unable to
 *         produce a result set.
 */
public static JFreeChart createChartFromQuery(Chart c)
        throws SQLException, QueryInitializationException, InterruptedException {
    logger.debug("Creating JFreeChart for Wabit chart " + c);
    ChartType chartType = c.getType();

    if (chartType == null) {
        logger.debug("Returning null (chart's type is not set)");
        return null;
    }

    final JFreeChart chart;
    if (chartType.getDatasetType().equals(DatasetType.CATEGORY)) {

        JFreeChart categoryChart = createCategoryChart(c);
        logger.debug("Made a new category chart: " + categoryChart);

        if (categoryChart != null && categoryChart.getPlot() instanceof CategoryPlot) {

            double rotationRads = Math.toRadians(c.getXAxisLabelRotation());
            CategoryLabelPositions clp;
            if (Math.abs(rotationRads) < 0.05) {
                clp = CategoryLabelPositions.STANDARD;
            } else if (rotationRads < 0) {
                clp = CategoryLabelPositions.createUpRotationLabelPositions(-rotationRads);
            } else {
                clp = CategoryLabelPositions.createDownRotationLabelPositions(rotationRads);
            }

            CategoryAxis domainAxis = categoryChart.getCategoryPlot().getDomainAxis();
            domainAxis.setMaximumCategoryLabelLines(5);
            domainAxis.setCategoryLabelPositions(clp);
        }

        chart = categoryChart;

    } else if (chartType.getDatasetType().equals(DatasetType.XY)) {

        JFreeChart xyChart = createXYChart(c);
        logger.debug("Made a new XY chart: " + xyChart);
        chart = xyChart;

    } else {

        throw new IllegalStateException("Unknown chart dataset type " + chartType.getDatasetType());

    }

    if (chart != null) {
        makeChartNice(chart);
    }

    return chart;
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartDualAxisGraphSource.java

@Override
public JFreeChart createChart(String title, String xLabel, String yLabel, CategoryDataset dataset,
        boolean legend, boolean graphToolTip) {
    PlotOrientation orientation = getParam(JFreeChartBarGraphSource.PLOT_ORIENTATION, PlotOrientation.class,
            JFreeChartBarGraphSource.DEFAULT_PLOT_ORIENTATION);
    // create the base plot, which is the time series graph
    JFreeChart dualAxisGraph = ChartFactory.createLineChart(title, xLabel, tsLabel, tsDataset, orientation,
            legend, graphToolTip, false);

    // add the bar graph data to the plot
    dualAxisGraph.getCategoryPlot().setDataset(1, barDataset);

    // create the second y-axis
    dualAxisGraph.getCategoryPlot().setRangeAxis(1, new NumberAxis(barLabel));
    dualAxisGraph.getCategoryPlot().mapDatasetToRangeAxis(1, 1);

    // create separate renderers for the time series and bar graphs to be
    // overlaid on the same plot
    CategoryLineGraphRenderer tsRenderer = new CategoryLineGraphRenderer(tsData);
    CategoryBarGraphRenderer barRenderer = new CategoryBarGraphRenderer(barData);
    setupLineRenderer(tsRenderer);/*from   w w  w . j a  v  a  2s .c  o  m*/
    setupBarRenderer(barRenderer);
    dualAxisGraph.getCategoryPlot().setRenderer(0, tsRenderer);
    dualAxisGraph.getCategoryPlot().setRenderer(1, barRenderer);

    return dualAxisGraph;
}