Example usage for org.jfree.chart ChartFactory createBarChart3D

List of usage examples for org.jfree.chart ChartFactory createBarChart3D

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createBarChart3D.

Prototype

public static JFreeChart createBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a bar chart with a 3D effect.

Usage

From source file:org.adempiere.apps.graph.ChartBuilder.java

private JFreeChart create3DBarChart() {
    JFreeChart chart = ChartFactory.createBarChart3D(chartModel.get_Translation(MChart.COLUMNNAME_Name), // chart title
            chartModel.get_Translation(MChart.COLUMNNAME_DomainLabel), // domain axis label
            chartModel.get_Translation(MChart.COLUMNNAME_RangeLabel), // range axis label
            getCategoryDataset(), // data
            X_AD_Chart.CHARTORIENTATION_Horizontal.equals(chartModel.getChartOrientation())
                    ? PlotOrientation.HORIZONTAL
                    : PlotOrientation.VERTICAL, // orientation
            chartModel.isDisplayLegend(), // include legend
            true, // tooltips?
            true // URLs?
    );/*from w w  w.  ja v a  2s .  c  om*/

    setupCategoryChart(chart);
    return chart;
}

From source file:view.ResultsPanel.java

public void showHistogram(List<ElementaryMode> modes) {

    //for the JTable
    DefaultTableModel tableModel = new DefaultTableModel();
    JTable tableResult = new JTable();
    tableResult.setModel(tableModel);/*  ww  w.ja v a2s . c om*/

    tableModel.addColumn("Reaction");
    tableModel.addColumn("Presence in the modes");

    tableResult.setAutoCreateRowSorter(true);

    Map<Reaction, Double> stats = new HashMap<Reaction, Double>();

    DecimalFormat df = new DecimalFormat("0.00");

    for (ElementaryMode em : modes) {
        for (Reaction r : em.getContent().keySet()) {
            if (em.getContent().containsKey(r)) {
                if (!stats.containsKey(r)) {
                    stats.put(r, 1.0);
                } else {
                    Reaction key = r;
                    Double value = stats.get(r) + 1;
                    stats.remove(key);
                    stats.put(key, value);
                }
            }
        }
    }

    for (Reaction r : stats.keySet()) {
        tableModel
                .addRow(new Object[] { r, String.valueOf(df.format(stats.get(r) * 100 / modes.size())) + "%" });
    }

    JFrame statisticFrame = new JFrame();
    statisticFrame.add(new JScrollPane(tableResult), BorderLayout.CENTER);
    statisticFrame.setVisible(true);
    statisticFrame.setSize(400, 350);
    statisticFrame.setTitle("Representativeness of each reaction");
    statisticFrame.setLocation(500, 600);

    //histogram
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Map<Integer, Integer> data = new TreeMap<Integer, Integer>();
    int maxSize = 0;
    for (ElementaryMode em : modes) {
        int modeLength = em.getContent().size();
        if (modeLength > maxSize) {
            maxSize = modeLength;
        }
        if (data.containsKey(modeLength)) {
            int value = data.get(modeLength) + 1;
            data.put(modeLength, value);
        } else {
            data.put(modeLength, 1);
        }
    }

    for (int i = 1; i < maxSize; i++) {
        if (!data.containsKey(i)) {
            data.put(i, 0);
        }
    }
    for (int key : data.keySet()) {
        dataset.addValue(Integer.valueOf((data.get(key))), "test", Integer.valueOf(key));
    }

    String plotTitle = "Number of reactions per elementary mode";
    String xaxis = "Reaction number";
    String yaxis = "Elementary mode number";
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = false;
    boolean toolTips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createBarChart3D(plotTitle, xaxis, yaxis, dataset, orientation, show,
            toolTips, urls);

    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis axis = plot.getDomainAxis();

    plot.getDomainAxis(0).setLabelFont(plot.getDomainAxis().getLabelFont().deriveFont(new Float(11)));

    ChartFrame frame = new ChartFrame("Elementary modes", chart);
    frame.setVisible(true);
    frame.setSize(400, 350);
    frame.setLocation(500, 100);

}

From source file:org.martus.client.swingui.actions.ActionMenuCharts.java

private JFreeChart create3DBarChart(HashMap<String, Integer> counts, String selectedFieldLabel)
        throws Exception {
    DefaultCategoryDataset dataset = createBarChartDataset(counts);

    boolean showLegend = false;
    boolean showTooltips = true;
    boolean showUrls = false;
    JFreeChart barChart = ChartFactory.createBarChart3D(getChartTitle(selectedFieldLabel), selectedFieldLabel,
            getYAxisTitle(), dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, showUrls);

    configureBarChartPlot(barChart);//from   w  ww  . ja  v  a  2 s  .  c o  m

    return barChart;
}

From source file:keel.GraphInterKeel.datacf.visualizeData.VisualizePanelCharts2D.java

private void ViewChartjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ViewChartjButtonActionPerformed
    // Show comparing chart
    if ((this.attribute1jComboBox.getSelectedIndex() == -1)
            || (this.attribute2jComboBox.getSelectedIndex() == -1)) {
        JOptionPane.showMessageDialog(this, "There are no attributes selected", "Error", 2);
    } else if (((VisualizePanel) (this.getParent()).getParent()).getData()
            .getAttributeTypeIndex(this.attribute1jComboBox.getSelectedIndex()).equals("nominal")
            && ((VisualizePanel) (this.getParent()).getParent()).getData()
                    .getAttributeTypeIndex(this.attribute2jComboBox.getSelectedIndex()).equals("nominal")) {
        // Error message
        JOptionPane.showMessageDialog(this, "Only one attribute can be nominal", "Error", 2);
    } else if (((VisualizePanel) (this.getParent()).getParent()).getData()
            .getAttributeTypeIndex(this.attribute1jComboBox.getSelectedIndex()).equals("nominal")) {
        // Nominal in x axis --> vertical
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        boolean legend = false;
        for (int i = 0; i < ((VisualizePanel) (this.getParent()).getParent()).getData().getNData(); i++) {
            String column = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                    this.attribute1jComboBox.getSelectedIndex());
            String row = "";
            if (((VisualizePanel) (this.getParent()).getParent()).getOutAttribute() != -1
                    && this.attribute1jComboBox
                            .getSelectedIndex() != ((VisualizePanel) (this.getParent()).getParent())
                                    .getOutAttribute()) {
                row = "Class " + ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        ((VisualizePanel) (this.getParent()).getParent()).getOutAttribute());
                legend = true;//www.j a  va2 s . c o m
            }
            String valor = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                    this.attribute2jComboBox.getSelectedIndex());
            if (valor != null && column != null) {
                if (dataset.getColumnIndex(column) == -1 || dataset.getRowIndex(row) == -1) {
                    dataset.addValue(Double.valueOf(valor).doubleValue(), row, column);
                } else {
                    dataset.incrementValue(Double.valueOf(valor).doubleValue(), row, column);
                }
            }
        }

        this.chart2 = ChartFactory.createBarChart3D("",
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute1jComboBox.getSelectedIndex()),
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute2jComboBox.getSelectedIndex()),
                dataset, PlotOrientation.VERTICAL, legend, false, false);
        this.chart2.setTitle(this.attribute1jComboBox.getSelectedItem().toString() + " vs "
                + this.attribute2jComboBox.getSelectedItem().toString());
        this.chart2.setBackgroundPaint(new Color(0xFFFFFF));
        BufferedImage image = this.chart2.createBufferedImage(600, 450);
        this.imagejLabel.setIcon(new ImageIcon(image));
        this.topdfjButton.setEnabled(true);
        this.topngjButton.setEnabled(true);
    } else if (((VisualizePanel) (this.getParent()).getParent()).getData()
            .getAttributeTypeIndex(this.attribute2jComboBox.getSelectedIndex()).equals("nominal")) {
        // Nominal in y axis --> horizontal
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        boolean legend = false;
        try {
            for (int i = 0; i < ((VisualizePanel) (this.getParent()).getParent()).getData().getNData(); i++) {
                String column = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute2jComboBox.getSelectedIndex());
                String row = "";
                if (((VisualizePanel) (this.getParent()).getParent()).getOutAttribute() != -1
                        && this.attribute2jComboBox
                                .getSelectedIndex() != ((VisualizePanel) (this.getParent()).getParent())
                                        .getOutAttribute()) {
                    row = "Class " + ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                            ((VisualizePanel) (this.getParent()).getParent()).getOutAttribute());
                    legend = true;
                }
                String valor = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute1jComboBox.getSelectedIndex());
                if (valor != null) {
                    if (dataset.getColumnIndex(column) == -1 || dataset.getRowIndex(row) == -1) {
                        dataset.addValue(Double.valueOf(valor).doubleValue(), row, column);
                    } else {
                        dataset.incrementValue(Double.valueOf(valor).doubleValue(), row, column);
                    }
                }
            }
        } catch (ArrayIndexOutOfBoundsException exp) {
            JOptionPane.showMessageDialog(this,
                    "The data set contains some errors. This attribute can not be visualized", "Error", 2);
        }
        this.chart2 = ChartFactory.createBarChart3D("",
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute2jComboBox.getSelectedIndex()),
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute1jComboBox.getSelectedIndex()),
                dataset, PlotOrientation.HORIZONTAL, legend, false, false);
        this.chart2.setTitle(this.attribute1jComboBox.getSelectedItem().toString() + " vs "
                + this.attribute2jComboBox.getSelectedItem().toString());
        this.chart2.setBackgroundPaint(new Color(0xFFFFFF));
        BufferedImage image = this.chart2.createBufferedImage(579, 330);
        this.imagejLabel.setIcon(new ImageIcon(image));
        this.topdfjButton.setEnabled(true);
        this.topngjButton.setEnabled(true);
    } else {
        XYSeriesCollection juegoDatos = new XYSeriesCollection();
        boolean legend = false;
        if (((VisualizePanel) (this.getParent()).getParent()).getOutAttribute() != -1) {
            legend = true;
            Vector outputRang = ((VisualizePanel) (this.getParent()).getParent()).getData()
                    .getRange(((VisualizePanel) (this.getParent()).getParent()).getOutAttribute());
            XYSeries series[] = new XYSeries[outputRang.size()];
            for (int i = 0; i < outputRang.size(); i++) {
                series[i] = new XYSeries("Class " + outputRang.elementAt(i));
                juegoDatos.addSeries(series[i]);
            }
            for (int i = 0; i < ((VisualizePanel) (this.getParent()).getParent()).getData().getNData(); i++) {
                int clase = outputRang.indexOf(((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getDataIndex(i, ((VisualizePanel) (this.getParent()).getParent()).getOutAttribute()));
                String valor1 = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute1jComboBox.getSelectedIndex());
                String valor2 = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute2jComboBox.getSelectedIndex());
                if (valor1 != null) {
                    series[clase].add(Double.valueOf(valor1).doubleValue(),
                            Double.valueOf(valor2).doubleValue());
                }
            }
        } else {
            XYSeries series = new XYSeries("Regresin");
            juegoDatos.addSeries(series);
            for (int i = 0; i < ((VisualizePanel) (this.getParent()).getParent()).getData().getNData(); i++) {
                String valor1 = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute1jComboBox.getSelectedIndex());
                String valor2 = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute2jComboBox.getSelectedIndex());
                if (valor1 != null) {
                    series.add(Double.valueOf(valor1).doubleValue(), Double.valueOf(valor2).doubleValue());
                }
            }

        }
        // Numeric values
        this.chart2 = ChartFactory.createScatterPlot("",
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute1jComboBox.getSelectedIndex()),
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute2jComboBox.getSelectedIndex()),
                juegoDatos, PlotOrientation.VERTICAL, legend, false, false);
        this.chart2.setTitle(this.attribute1jComboBox.getSelectedItem().toString() + " vs "
                + this.attribute2jComboBox.getSelectedItem().toString());
        this.chart2.setBackgroundPaint(new Color(0xFFFFFF));
        BufferedImage image = this.chart2.createBufferedImage(579, 330);
        this.imagejLabel.setIcon(new ImageIcon(image));
        this.topdfjButton.setEnabled(true);
        this.topngjButton.setEnabled(true);
    }
}

From source file:org.leo.benchmark.Benchmark.java

/**
 * Create a chartpanel/*from w w w  . j a v  a  2  s  .c  o  m*/
 * 
 * @param title title
 * @param dataName name of the data
 * @param clazzResult data mapped by classes
 * @param catItemLabelGenerator label generator
 * @return the chartPanel
 */
@SuppressWarnings("serial")
private ChartPanel createChart(String title, String dataName,
        Map<Class<? extends Collection<?>>, Long> clazzResult,
        AbstractCategoryItemLabelGenerator catItemLabelGenerator) {
    // sort data by class name
    List<Class<? extends Collection<?>>> clazzes = new ArrayList<Class<? extends Collection<?>>>(
            clazzResult.keySet());
    Collections.sort(clazzes, new Comparator<Class<? extends Collection<?>>>() {
        @Override
        public int compare(Class<? extends Collection<?>> o1, Class<? extends Collection<?>> o2) {
            return o1.getCanonicalName().compareTo(o2.getCanonicalName());
        }
    });
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    // add the data to the dataset
    for (Class<? extends Collection<?>> clazz : clazzes) {
        dataSet.addValue(clazzResult.get(clazz), clazz.getName(), title.split(" ")[0]);
    }
    // create the chart
    JFreeChart chart = ChartFactory.createBarChart3D(null, null, dataName, dataSet, PlotOrientation.HORIZONTAL,
            false, true, false);
    chart.addSubtitle(new TextTitle(title));
    // some customization in the style
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(new Color(250, 250, 250));
    plot.setDomainGridlinePaint(new Color(255, 200, 200));
    plot.setRangeGridlinePaint(Color.BLUE);
    plot.getDomainAxis().setVisible(false);
    plot.getRangeAxis().setLabelFont(new Font("arial", Font.PLAIN, 10));
    BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
    // display the class name in the bar chart
    for (int i = 0; i < clazzResult.size(); i++) {
        renderer.setSeriesItemLabelGenerator(i, new StandardCategoryItemLabelGenerator() {
            @Override
            public String generateLabel(CategoryDataset dataset, int row, int column) {
                String label = " " + dataset.getRowKey(row).toString();
                if (dataset.getValue(row, column).equals(timeout * 1000000)) {
                    label += " (Timeout)";
                }
                return label;
            }
        });
        renderer.setSeriesItemLabelsVisible(i, true);
        ItemLabelPosition itemPosition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER_LEFT,
                TextAnchor.CENTER_LEFT, 0.0);
        renderer.setSeriesPositiveItemLabelPosition(i, itemPosition);
        renderer.setSeriesNegativeItemLabelPosition(i, itemPosition);
    }
    ItemLabelPosition itemPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_LEFT,
            TextAnchor.CENTER_LEFT, 0.0);
    renderer.setPositiveItemLabelPositionFallback(itemPosition);
    renderer.setNegativeItemLabelPositionFallback(itemPosition);
    renderer.setShadowVisible(false);

    // create the chartpanel
    ChartPanel chartPanel = new ChartPanel(chart);
    chart.setBorderVisible(true);
    return chartPanel;
}

From source file:my.estadistico.Grafica.java

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
    try {// w  ww  .  j a v  a  2 s .  c  om
        this.datos();//Obtiene los datos
        JFreeChart chart = ChartFactory.createBarChart3D("", "", "", dataset, PlotOrientation.HORIZONTAL, false,
                false, false);
        CategoryPlot catPlot = chart.getCategoryPlot();
        catPlot.setRangeGridlinePaint(Color.BLACK);
        this.mostrar(chart);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(rootPane, "FAVOR DE INGRESAR DATOS");
    }
    // TODO add your handling code here:
}

From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java

private byte[] generateBarChart(String siteId, CategoryDataset dataset, int width, int height, boolean render3d,
        float transparency, boolean itemLabelsVisible, boolean smallFontInDomainAxis) {
    JFreeChart chart = null;//from w  ww.  ja v a 2  s  .c om
    if (render3d)
        chart = ChartFactory.createBarChart3D(null, null, null, dataset, PlotOrientation.VERTICAL, true, false,
                false);
    else
        chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, false,
                false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // set transparency
    plot.setForegroundAlpha(transparency);

    // set background
    chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor()));

    // set chart border
    chart.setPadding(new RectangleInsets(10, 5, 5, 5));
    chart.setBorderVisible(true);
    chart.setBorderPaint(parseColor("#cccccc"));

    // allow longer legends (prevent truncation)
    plot.getDomainAxis().setMaximumCategoryLabelLines(50);
    plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(1.0f);

    // set antialias
    chart.setAntiAlias(true);

    // set domain axis font size
    if (smallFontInDomainAxis && !canUseNormalFontSize(width)) {
        plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 8));
        plot.getDomainAxis().setCategoryMargin(0.05);
    }

    // set bar outline
    BarRenderer barrenderer = (BarRenderer) plot.getRenderer();
    barrenderer.setDrawBarOutline(true);
    if (smallFontInDomainAxis && !canUseNormalFontSize(width))
        barrenderer.setItemMargin(0.05);
    else
        barrenderer.setItemMargin(0.10);

    // item labels
    if (itemLabelsVisible) {
        plot.getRangeAxis().setUpperMargin(0.2);
        barrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
            private static final long serialVersionUID = 1L;

            @Override
            public String generateLabel(CategoryDataset dataset, int row, int column) {
                Number n = dataset.getValue(row, column);
                if (n.doubleValue() != 0) {
                    if ((double) n.intValue() == n.doubleValue())
                        return Integer.toString(n.intValue());
                    else
                        return Double.toString(Util.round(n.doubleValue(), 1));
                }
                return "";
            }
        });
        barrenderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 8));
        barrenderer.setItemLabelsVisible(true);
    }

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        LOG.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}

From source file:ro.nextreports.engine.chart.JFreeChartExporter.java

private JFreeChart createBarChart(boolean horizontal, boolean stacked, boolean isCombo) throws QueryException {
    barDataset = new DefaultCategoryDataset();
    String chartTitle = replaceParameters(chart.getTitle().getTitle());
    chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language));
    Object[] charts;// w w  w  .j a  v  a 2s .c o  m
    List<String> legends;
    Object[] lineCharts = null;
    String lineLegend = null;
    if (isCombo) {
        lineCharts = new Object[1];
        if (chart.getYColumnsLegends().size() < chart.getYColumns().size()) {
            lineLegend = "";
        } else {
            lineLegend = chart.getYColumnsLegends().get(chart.getYColumns().size() - 1);
        }
        charts = new Object[chart.getYColumns().size() - 1];
        legends = chart.getYColumnsLegends().subList(0, chart.getYColumns().size() - 1);
    } else {
        charts = new Object[chart.getYColumns().size()];
        legends = chart.getYColumnsLegends();
    }
    boolean hasLegend = false;
    for (int i = 0; i < charts.length; i++) {
        String legend = "";
        try {
            legend = replaceParameters(legends.get(i));
            legend = StringUtil.getI18nString(legend, I18nUtil.getLanguageByName(chart, language));
        } catch (IndexOutOfBoundsException ex) {
            // no legend set
        }
        // Important : must have default different legends used in barDataset.addValue
        if ((legend == null) || "".equals(legend.trim())) {
            legend = DEFAULT_LEGEND_PREFIX + String.valueOf(i + 1);
        } else {
            hasLegend = true;
        }
        charts[i] = legend;
    }
    if (isCombo) {
        String leg = "";
        if (lineLegend != null) {
            leg = replaceParameters(lineLegend);
        }
        lineCharts[0] = leg;
    }

    byte style = chart.getType().getStyle();
    JFreeChart jfreechart;

    String xLegend = StringUtil.getI18nString(replaceParameters(chart.getXLegend().getTitle()),
            I18nUtil.getLanguageByName(chart, language));
    String yLegend = StringUtil.getI18nString(replaceParameters(chart.getYLegend().getTitle()),
            I18nUtil.getLanguageByName(chart, language));
    PlotOrientation plotOrientation = horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL;
    if (stacked) {
        jfreechart = ChartFactory.createStackedBarChart(chartTitle, // chart title
                xLegend, // x-axis Label
                yLegend, // y-axis Label
                barDataset, // data
                plotOrientation, // orientation
                true, // include legend
                true, // tooltips
                false // URLs
        );
    } else {
        switch (style) {
        case ChartType.STYLE_BAR_PARALLELIPIPED:
        case ChartType.STYLE_BAR_CYLINDER:
            jfreechart = ChartFactory.createBarChart3D(chartTitle, // chart title
                    xLegend, // x-axis Label
                    yLegend, // y-axis Label
                    barDataset, // data
                    plotOrientation, // orientation
                    true, // include legend
                    true, // tooltips
                    false // URLs
            );
            break;
        default:
            jfreechart = ChartFactory.createBarChart(chartTitle, // chart title
                    xLegend, // x-axis Label
                    yLegend, // y-axis Label
                    barDataset, // data
                    plotOrientation, // orientation
                    true, // include legend
                    true, // tooltips
                    false // URLs
            );
            break;
        }
    }

    if (style == ChartType.STYLE_BAR_CYLINDER) {
        ((CategoryPlot) jfreechart.getPlot()).setRenderer(new CylinderRenderer());
    }

    // hide legend if necessary
    if (!hasLegend) {
        jfreechart.removeLegend();
    }

    // hide border
    jfreechart.setBorderVisible(false);

    // title
    setTitle(jfreechart);

    // chart colors & values shown on bars
    boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart();
    CategoryPlot plot = (CategoryPlot) jfreechart.getPlot();
    plot.setForegroundAlpha(transparency);
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    DecimalFormat decimalformat;
    DecimalFormat percentageFormat;
    if (chart.getYTooltipPattern() == null) {
        decimalformat = new DecimalFormat("#");
        percentageFormat = new DecimalFormat("0.00%");
    } else {
        decimalformat = new DecimalFormat(chart.getYTooltipPattern());
        percentageFormat = decimalformat;
    }
    for (int i = 0; i < charts.length; i++) {
        renderer.setSeriesPaint(i, chart.getForegrounds().get(i));
        if (showValues) {
            renderer.setSeriesItemLabelsVisible(i, true);
            renderer.setSeriesItemLabelGenerator(i,
                    new StandardCategoryItemLabelGenerator("{2}", decimalformat, percentageFormat));
        }
    }

    if (showValues) {
        // increase a little bit the range axis to view all item label values over bars
        plot.getRangeAxis().setUpperMargin(0.2);
    }

    // grid axis visibility & colors 
    if ((chart.getXShowGrid() != null) && !chart.getXShowGrid()) {
        plot.setDomainGridlinesVisible(false);
    } else {
        if (chart.getXGridColor() != null) {
            plot.setDomainGridlinePaint(chart.getXGridColor());
        } else {
            plot.setDomainGridlinePaint(Color.BLACK);
        }
    }
    if ((chart.getYShowGrid() != null) && !chart.getYShowGrid()) {
        plot.setRangeGridlinesVisible(false);
    } else {
        if (chart.getYGridColor() != null) {
            plot.setRangeGridlinePaint(chart.getYGridColor());
        } else {
            plot.setRangeGridlinePaint(Color.BLACK);
        }
    }

    // chart background
    plot.setBackgroundPaint(chart.getBackground());

    // labels color
    plot.getDomainAxis().setTickLabelPaint(chart.getXColor());
    plot.getRangeAxis().setTickLabelPaint(chart.getYColor());

    // legend color
    plot.getDomainAxis().setLabelPaint(chart.getXLegend().getColor());
    plot.getRangeAxis().setLabelPaint(chart.getYLegend().getColor());

    // legend font
    plot.getDomainAxis().setLabelFont(chart.getXLegend().getFont());
    plot.getRangeAxis().setLabelFont(chart.getYLegend().getFont());

    // axis color
    plot.getDomainAxis().setAxisLinePaint(chart.getxAxisColor());
    plot.getRangeAxis().setAxisLinePaint(chart.getyAxisColor());

    // hide labels
    if ((chart.getXShowLabel() != null) && !chart.getXShowLabel()) {
        plot.getDomainAxis().setTickLabelsVisible(false);
        plot.getDomainAxis().setTickMarksVisible(false);
    }
    if ((chart.getYShowLabel() != null) && !chart.getYShowLabel()) {
        plot.getRangeAxis().setTickLabelsVisible(false);
        plot.getRangeAxis().setTickMarksVisible(false);
    }

    if (chart.getType().getStyle() == ChartType.STYLE_NORMAL) {
        // no shadow
        renderer.setShadowVisible(false);
        // no gradient
        renderer.setBarPainter(new StandardBarPainter());
    }

    // label orientation
    CategoryAxis domainAxis = plot.getDomainAxis();
    if (chart.getXorientation() == Chart.VERTICAL) {
        domainAxis
                .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2));
    } else if (chart.getXorientation() == Chart.DIAGONAL) {
        domainAxis
                .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4));
    } else if (chart.getXorientation() == Chart.HALF_DIAGONAL) {
        domainAxis
                .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8));
    }

    // labels fonts
    domainAxis.setTickLabelFont(chart.getXLabelFont());
    plot.getRangeAxis().setTickLabelFont(chart.getYLabelFont());

    createChart(plot.getRangeAxis(), charts);

    if (isCombo) {
        addLineChartOverBar(jfreechart, lineCharts, lineLegend);
    }

    return jfreechart;
}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

protected JFreeChart createBar3DChart() throws JRException {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createBarChart3D(
            (String) evaluateExpression(getChart().getTitleExpression()),
            (String) evaluateExpression(((JRBar3DPlot) getPlot()).getCategoryAxisLabelExpression()),
            (String) evaluateExpression(((JRBar3DPlot) getPlot()).getValueAxisLabelExpression()),
            (CategoryDataset) getDataset(), getPlot().getOrientation(), isShowLegend(), true, false);

    configureChart(jfreeChart, getPlot());

    CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot();
    JRBar3DPlot bar3DPlot = (JRBar3DPlot) getPlot();

    BarRenderer3D barRenderer3D = new BarRenderer3D(
            bar3DPlot.getXOffsetDouble() == null ? BarRenderer3D.DEFAULT_X_OFFSET
                    : bar3DPlot.getXOffsetDouble().doubleValue(),
            bar3DPlot.getYOffsetDouble() == null ? BarRenderer3D.DEFAULT_Y_OFFSET
                    : bar3DPlot.getYOffsetDouble().doubleValue());

    boolean isShowLabels = bar3DPlot.getShowLabels() == null ? false : bar3DPlot.getShowLabels().booleanValue();
    barRenderer3D.setBaseItemLabelsVisible(isShowLabels);
    if (isShowLabels) {
        JRItemLabel itemLabel = bar3DPlot.getItemLabel();
        Integer baseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap,
                ChartThemesConstants.BASEFONT_SIZE);
        JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : null;
        barRenderer3D.setBaseItemLabelFont(getFont(new JRBaseFont(getChart(), null), font, baseFontSize));

        if (itemLabel != null) {
            if (itemLabel.getColor() != null) {
                barRenderer3D.setBaseItemLabelPaint(itemLabel.getColor());
            } else {
                barRenderer3D.setBaseItemLabelPaint(getChart().getForecolor());
            }//  ww w .  j  ava 2s. c om
            //            categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor());
            //            if(itemLabel.getMask() != null)
            //            {
            //               barRenderer3D.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            //                     StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, 
            //                     new DecimalFormat(itemLabel.getMask())));
            //            }
            //            else
            //            {
            barRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator());
            //            }
        } else {
            barRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator());
            barRenderer3D.setBaseItemLabelPaint(getChart().getForecolor());
        }
    }

    categoryPlot.setRenderer(barRenderer3D);

    // Handle the axis formating for the category axis
    configureAxis(categoryPlot.getDomainAxis(), bar3DPlot.getCategoryAxisLabelFont(),
            bar3DPlot.getCategoryAxisLabelColor(), bar3DPlot.getCategoryAxisTickLabelFont(),
            bar3DPlot.getCategoryAxisTickLabelColor(), bar3DPlot.getCategoryAxisTickLabelMask(),
            bar3DPlot.getCategoryAxisVerticalTickLabels(), bar3DPlot.getOwnCategoryAxisLineColor(), false,
            (Comparable) evaluateExpression(bar3DPlot.getDomainAxisMinValueExpression()),
            (Comparable) evaluateExpression(bar3DPlot.getDomainAxisMaxValueExpression()));

    // Handle the axis formating for the value axis
    configureAxis(categoryPlot.getRangeAxis(), bar3DPlot.getValueAxisLabelFont(),
            bar3DPlot.getValueAxisLabelColor(), bar3DPlot.getValueAxisTickLabelFont(),
            bar3DPlot.getValueAxisTickLabelColor(), bar3DPlot.getValueAxisTickLabelMask(),
            bar3DPlot.getValueAxisVerticalTickLabels(), bar3DPlot.getOwnValueAxisLineColor(), true,
            (Comparable) evaluateExpression(bar3DPlot.getRangeAxisMinValueExpression()),
            (Comparable) evaluateExpression(bar3DPlot.getRangeAxisMaxValueExpression()));

    return jfreeChart;
}

From source file:UserInterface.PatientRole.ManageMyVitalSignsAndFitnessRecordJPanel.java

private void createChart() {
    DefaultCategoryDataset vitalSignDataset = new DefaultCategoryDataset();
    int selectedRow = viewVitalSignsJTable1.getSelectedRow();
    ArrayList<Record> recordList = patient.getRecordHistory().getRecordList();
    /*At least 2 vital sign records needed to show chart */
    if (recordList.isEmpty() || recordList.size() == 1) {
        JOptionPane.showMessageDialog(this,
                "No Fitness Record or only one fitness record found. At least 2 fitness records needed to show chart!",
                "Warning", JOptionPane.INFORMATION_MESSAGE);
        return;/*from   w  w w .ja  v a 2  s .  c o  m*/
    }
    for (Record record : recordList) {
        vitalSignDataset.addValue(record.getStandTime(), "StandTime", record.getDate());
        vitalSignDataset.addValue(record.getMoveTime(), "MoveTime", record.getDate());
        vitalSignDataset.addValue(record.getExcerciseTime(), "ExcerciseTime", record.getDate());
        vitalSignDataset.addValue(record.getTotalTime(), "TotalTime", record.getDate());
    }

    JFreeChart vitalSignChart = ChartFactory.createBarChart3D("Fitness Record Chart", "Time Stamp",
            "Time(mins)", vitalSignDataset, PlotOrientation.VERTICAL, true, false, false);
    vitalSignChart.setBackgroundPaint(Color.white);
    CategoryPlot vitalSignChartPlot = vitalSignChart.getCategoryPlot();
    vitalSignChartPlot.setBackgroundPaint(Color.lightGray);

    CategoryAxis vitalSignDomainAxis = vitalSignChartPlot.getDomainAxis();
    vitalSignDomainAxis
            .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    NumberAxis vitalSignRangeAxis = (NumberAxis) vitalSignChartPlot.getRangeAxis();
    vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    ChartFrame chartFrame = new ChartFrame("Chart", vitalSignChart);
    chartFrame.setVisible(true);
    chartFrame.setSize(500, 500);
}