Example usage for org.jfree.data.category DefaultCategoryDataset setValue

List of usage examples for org.jfree.data.category DefaultCategoryDataset setValue

Introduction

In this page you can find the example usage for org.jfree.data.category DefaultCategoryDataset setValue.

Prototype

public void setValue(double value, Comparable rowKey, Comparable columnKey) 

Source Link

Document

Adds or updates a value in the table and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:graph.plotter.LineGraph.java

/**
 * This is the main working button for this class... It creates Line Graph analyZing whole data set
 * /*from   w w  w  .j ava2  s .c om*/
 * @param evt 
 */
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    // TODO add your handling code here:
    try {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        int i;
        i = 0;
        String genre = " ";
        if (button1 == 2) {
            if (button2 == 1)
                while (i < cnt) {
                    double aa = Double.parseDouble(Table.getModel().getValueAt(i, 1).toString());
                    String str = Table.getModel().getValueAt(i, 0).toString();
                    dataset.setValue(new Double(aa), genre, str);
                    i++;
                    //genre+=" ";

                }
            else {
                try {
                    BufferedReader br = new BufferedReader(new FileReader(jTextField4.getText()));
                    String Line;
                    while ((Line = br.readLine()) != null) {
                        String[] value = Line.split(",");
                        double val = Double.parseDouble(value[1]);

                        dataset.setValue(new Double(val), genre, value[0]);
                        //   genre+=" ";
                        ////System.out.println(value[0]);
                    }
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(LineGraph.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(LineGraph.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        } else if (button1 == 1) {

            String input = jTextField1.getText();
            input = input.replaceAll("sin", "@");
            input = input.replaceAll("cos", "#");
            input = input.replaceAll("tan", "Q");
            input = input.replaceAll("log", "~");
            input = input.replaceAll("e", "&");
            input = input.replaceAll("cosec", "r");
            input = input.replaceAll("cot", "w");
            input = input.replaceAll("sec", "y");

            //System.out.println(input);
            int len;
            len = input.length();
            String so = ".";

            for (ind = 0; ind < 360; ind++) {
                String gini = input;

                String sa = Integer.toString(ind);
                gini = gini.replaceAll("X", sa);

                Polish polish = new Polish(gini);
                double Calculate = Polish.Calculate();
                dataset.setValue(new Double(Calculate), ".", sa);
                so += ".";
            }

        }

        JFreeChart chart = ChartFactory.createLineChart("Line Graph", "X - Axis", "Y - Axis", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.YELLOW);
        p.setBackgroundPaint(Color.BLACK);
        ChartFrame frame = new ChartFrame("Line Chart", chart);
        jButto1 = new JButton("Save");

        frame.setLayout(new BorderLayout());

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());

        GridBagConstraints gc = new GridBagConstraints();
        gc.gridx = 1;
        gc.gridy = 0;

        panel.add(jButto1, gc);

        frame.add(panel, BorderLayout.SOUTH);

        jButto1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                try {
                    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
                    final File file1 = new File("Line_Chart.png");
                    ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
                } catch (Exception ex) {

                }

            }
        });
        frame.setVisible(true);

        frame.setSize(858, 513);
    } catch (Exception e) {

    }
}

From source file:com.polivoto.vistas.Charts.java

private void crearBarChart(Pregunta pregunta) {
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBackground(Color.white);
    panelGrafica.add(panel);/*from ww w .  j av  a2  s.com*/

    DefaultCategoryDataset data = new DefaultCategoryDataset();
    // Fuente de Datos

    //Calcular el nmero N de perfiles. Si N=1, no discriminar por pestanas. 
    //Si son N perfiles (N>2), hacer N+1 pestanas (la ltima representa la
    //suma de los resultados sin segregacin.
    int n = pregunta.obtenerCantidadDePerfiles();
    System.out.println(" n " + n);
    if (n > 1) {
        for (int i = 0; i < n; i++) {
            List<Opcion> opciones = pregunta.obtenerResultadoPorPerfil(i).getOpciones();
            for (Opcion opc : opciones) {
                data.setValue(opc.getCantidad(), opc.getNombre(),
                        pregunta.obtenerResultadoPorPerfil(i).getPerfil());
            }
        }
    }
    for (int i = 0; i < pregunta.obtenerCantidadDeOpciones(); i++) {
        Opcion opc = pregunta.obtenerOpcion(i);
        data.setValue(opc.getCantidad(), opc.getNombre(), "Todos");
    }

    // Creando el Grafico       
    JFreeChart chart = ChartFactory.createBarChart("\n" + pregunta.getTitulo() + "\n", "Perfil",
            "Total de votos", data, PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );

    //chart.setBackgroundPaint(Color.white);
    chart.getTitle().setFont(new Font("Roboto", 0, 28));

    //chart.addSubtitle(new TextTitle("Titulo jajaja"));
    //chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white));
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.setOutlineVisible(false);

    ChartPanel barChart = new ChartPanel(chart);
    barChart.setBounds(panel.getVisibleRect());

    //barChart.setPreferredSize(panelGrafica.getSize());
    //barChart.setBounds(panel.getVisibleRect());

    //Colores de Barras
    Paint[] colors = { new Color(124, 181, 236), new Color(244, 91, 91), new Color(144, 237, 125),
            new Color(67, 67, 72), new Color(247, 163, 92), new Color(128, 133, 233), new Color(241, 92, 128),
            new Color(228, 211, 84), new Color(43, 144, 143), new Color(145, 232, 225) };

    ((org.jfree.chart.renderer.category.BarRenderer) plot.getRenderer())
            .setBarPainter(new StandardBarPainter()); // Quita Efecto luz
    BarRenderer renderer = new BarRenderer(colors);
    renderer.setColor(plot, data);

    //Numeros sobre barras
    CategoryItemRenderer renderizar;
    renderizar = plot.getRenderer();
    renderizar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderizar.setBaseItemLabelsVisible(true);
    renderizar.setItemLabelFont(new Font("Roboto", 0, 18));

    //Valores eje Y
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setLabelFont(new Font("Roboto", 0, 17));
    rangeAxis.setTickLabelFont(new Font("Roboto", 0, 17));

    //Diseo categorias
    org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLabelFont(new Font("Roboto", 0, 17));
    domainAxis.setTickLabelFont(new Font("Roboto", 0, 17));
    /*domainAxis.setTickLabelPaint(new Color(160, 163, 165));
     domainAxis.setCategoryLabelPositionOffset(4);
     domainAxis.setLowerMargin(0);
     domainAxis.setUpperMargin(0);
     domainAxis.setCategoryMargin(0.2);
     */

    //Leyendas
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.BOTTOM);
    Font nwfont = new Font("Roboto", 0, 18);
    legend.setItemFont(nwfont);
    legend.setBorder(0, 0, 0, 0);
    legend.setBackgroundPaint(Color.WHITE);
    legend.setItemLabelPadding(new RectangleInsets(8, 8, 8, 15));

    /*
     plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{1} {0}"));
     plot.setLegendItemShape(new Rectangle(25, 25));
     */
    // Pintar
    panel.removeAll();
    panel.add(barChart);
    panel.repaint();
    panel.revalidate();
    panelGrafica.repaint();
    panelGrafica.revalidate();
}

From source file:lenscorrection.Distortion_Correction.java

public void evaluateCorrection(final List<List<PointMatch>> inliers) {
    IJ.showStatus("Evaluating Distortion Correction");
    final double[][] original = new double[sp.numberOfImages][2];
    final double[][] corrected = new double[sp.numberOfImages][2];

    for (int i = sp.firstImageIndex; i < sp.numberOfImages; i++) {
        original[i] = evaluateCorrectionXcorr(i, sp.source_dir);
        corrected[i] = evaluateCorrectionXcorr(i, sp.target_dir);
    }/*  ww  w  .  jav a2 s.  com*/
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    final DefaultCategoryDataset datasetGain = new DefaultCategoryDataset();
    final DefaultCategoryDataset datasetGrad = new DefaultCategoryDataset();

    for (int i = 0; i < (original.length); ++i) {
        dataset.setValue(Math.abs(original[i][0]), "before", "image" + i);
        dataset.setValue(Math.abs(corrected[i][0]), "after", "image" + i);
        datasetGrad.setValue(Math.abs(original[i][1]), "before", "image" + i);
        datasetGrad.setValue(Math.abs(corrected[i][1]), "after", "image" + i);

        datasetGain.setValue(Math.abs(corrected[i][0]) - Math.abs(original[i][0]), "gray", "image" + i);
        datasetGain.setValue(Math.abs(corrected[i][1]) - Math.abs(original[i][1]), "grad", "image" + i);
    }

    final JFreeChart chart = ChartFactory.createBarChart("Xcorr before and after correction", "ImageNumber",
            "Xcorr", dataset, PlotOrientation.VERTICAL, false, true, false);
    final ImagePlus imp = new ImagePlus("Xcorr before and after correction Plot",
            chart.createBufferedImage(500, 300));
    imp.show();

    final JFreeChart chartGrad = ChartFactory.createBarChart("XcorrGradient before and after correction",
            "ImageNumber", "Xcorr", datasetGrad, PlotOrientation.VERTICAL, false, true, false);
    final ImagePlus impGrad = new ImagePlus("XcorrGradient before and after correction Plot",
            chartGrad.createBufferedImage(500, 300));
    impGrad.show();

    final JFreeChart chartGain = ChartFactory.createBarChart("Gain in Xcorr", "ImageNumber", "Xcorr",
            datasetGain, PlotOrientation.VERTICAL, false, true, false);
    final ImagePlus impGain = new ImagePlus("Gain in Xcorr Plot", chartGain.createBufferedImage(500, 300));
    impGain.show();

    visualizePoints(inliers);

    //write xcorr data to file
    String original0 = "", original1 = "", corrected0 = "", corrected1 = "", gain0 = "", gain1 = "";
    for (int i = 0; i < (original.length); ++i) {
        original0 = original0 + Double.toString(original[i][0]) + "; ";
        original1 = original1 + Double.toString(original[i][1]) + "; ";
        corrected0 = corrected0 + Double.toString(corrected[i][0]) + "; ";
        corrected1 = corrected1 + Double.toString(corrected[i][1]) + "; ";
        gain0 = gain0 + Double.toString(Math.abs(corrected[i][0]) - Math.abs(original[i][0])) + "; ";
        gain1 = gain1 + Double.toString(Math.abs(corrected[i][1]) - Math.abs(original[i][1])) + "; ";
    }

    try {
        final BufferedWriter out = new BufferedWriter(new FileWriter(sp.source_dir + "xcorrData.log"));

        out.write(original0);
        out.newLine();
        out.newLine();
        out.write(original1);
        out.newLine();
        out.newLine();
        out.write(corrected0);
        out.newLine();
        out.newLine();
        out.write(corrected1);
        out.newLine();
        out.newLine();
        out.write(gain0);
        out.newLine();
        out.newLine();
        out.write(gain1);
        out.newLine();
        out.close();
    } catch (final Exception e) {
        System.err.println("Error: " + e.getMessage());
    }
    ;
}

From source file:UserInterface.FinanceRole.DonateToPoorPeopleJPanel.java

private void populateTransactionTable(Person objPerson) {

    //Chart//from w w  w .  ja  va2s. c  om
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    //Table
    DefaultTableModel dtm = (DefaultTableModel) donationHistoryJTable.getModel();
    dtm.setRowCount(0);

    if (objPerson != null) {
        for (Transaction objTransaction : objPerson.getObjPoorPeopleTransactionDirectory()
                .getTransactionList()) {

            if (objTransaction.getTransactionSource()
                    .equals(Transaction.TransactionSourceType.FromWorldEnterprise.getValue())) {

                Object row[] = new Object[3];
                row[0] = objTransaction;
                row[1] = "$ " + objTransaction.getTransactionBDAmount();
                row[2] = objTransaction.getTransactionDateToDisplay();

                dtm.addRow(row);

                dataSet.setValue(objTransaction.getTransactionBDAmount(), "Amount",
                        objTransaction.getTransactionDateToDisplay());
            }
        }

        JFreeChart chart = ChartFactory.createBarChart3D("Overview of entire Transaction", "Transaction Date",
                "Amount in USD $", dataSet, PlotOrientation.VERTICAL, false, true, false);

        CategoryPlot plot = chart.getCategoryPlot();
        plot.setRangeGridlinePaint(Color.black);

        ChartPanel myChart = new ChartPanel(chart);
        transferDetailsJPanel.setLayout(new java.awt.BorderLayout());
        transferDetailsJPanel.add(myChart, BorderLayout.CENTER);
        transferDetailsJPanel.validate();

        transferDetailsJPanel.setVisible(true);
    } else {

        transferDetailsJPanel.setVisible(false);

    }
}

From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java

/**
 * onClick button Bar Chart 3D. <br>
 * /*ww w. ja  va2s .c o  m*/
 * @param event
 * @throws IOException
 */
public void onClick$button_CustomerChart_BarChart3D(Event event) throws InterruptedException, IOException {
    // logger.debug(event.toString());

    div_chartArea.getChildren().clear();

    // get the customer ID for which we want show a chart
    long kunId = getCustomer().getId();

    // get a list of data
    List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId);

    if (kunAmountList.size() > 0) {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        for (ChartData chartData : kunAmountList) {

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(chartData.getChartKunInvoiceDate());

            int month = calendar.get(Calendar.MONTH) + 1;
            int year = calendar.get(Calendar.YEAR);
            String key = String.valueOf(month) + "/" + String.valueOf(year);

            BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3);
            String amount = String.valueOf(bd.doubleValue());

            // fill the data
            dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), key + " " + amount,
                    key + " " + amount);
        }

        String title = "Monthly amount for year 2009";
        PlotOrientation po = PlotOrientation.VERTICAL;
        JFreeChart chart = ChartFactory.createBarChart3D(title, "Month", "Amount", dataset, po, true, true,
                true);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setForegroundAlpha(0.5f);
        BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null);
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage chartImage = new AImage("Bar Chart 3D", bytes);

        Image img = new Image();
        img.setContent(chartImage);
        img.setParent(div_chartArea);

    } else {

        div_chartArea.getChildren().clear();

        Label label = new Label();
        label.setValue("This customer have no data for showing in a chart!");

        label.setParent(div_chartArea);
    }
}

From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java

/**
 * onClick button Bar Chart. <br>/*from  w  ww. ja  v a 2 s. c  o m*/
 * 
 * @param event
 * @throws IOException
 */
public void onClick$button_CustomerChart_BarChart(Event event) throws InterruptedException, IOException {
    // logger.debug(event.toString());

    div_chartArea.getChildren().clear();

    // get the customer ID for which we want show a chart
    long kunId = getCustomer().getId();

    // get a list of data
    List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId);

    if (kunAmountList.size() > 0) {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        for (ChartData chartData : kunAmountList) {

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(chartData.getChartKunInvoiceDate());

            int month = calendar.get(Calendar.MONTH) + 1;
            int year = calendar.get(Calendar.YEAR);
            String key = String.valueOf(month) + "/" + String.valueOf(year);

            BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3);
            String amount = String.valueOf(bd.doubleValue());

            // fill the data
            dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), key + " " + amount,
                    key + " " + amount);
        }

        String title = "Monthly amount for year 2009";
        PlotOrientation po = PlotOrientation.VERTICAL;
        JFreeChart chart = ChartFactory.createBarChart(title, "Month", "Amount", dataset, po, true, true, true);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setForegroundAlpha(0.5f);

        BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null);
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage chartImage = new AImage("Bar Chart", bytes);

        Image img = new Image();
        img.setContent(chartImage);
        img.setParent(div_chartArea);

    } else {

        div_chartArea.getChildren().clear();

        Label label = new Label();
        label.setValue("This customer have no data for showing in a chart!");

        label.setParent(div_chartArea);

    }
}

From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java

/**
 * onClick button Stacked Bar Chart. <br>
 * /*from w w  w  . j  a v a  2s  .  com*/
 * @param event
 * @throws IOException
 */
public void onClick$button_CustomerChart_StackedBar(Event event) throws InterruptedException, IOException {
    // logger.debug(event.toString());

    div_chartArea.getChildren().clear();

    // get the customer ID for which we want show a chart
    long kunId = getCustomer().getId();

    // get a list of data
    List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId);

    if (kunAmountList.size() > 0) {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        for (ChartData chartData : kunAmountList) {

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(chartData.getChartKunInvoiceDate());

            int month = calendar.get(Calendar.MONTH) + 1;
            int year = calendar.get(Calendar.YEAR);
            String key = String.valueOf(month) + "/" + String.valueOf(year);

            BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3);
            String amount = String.valueOf(bd.doubleValue());

            // fill the data
            dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), key + " " + amount,
                    key + " " + amount);
        }

        String title = "Monthly amount for year 2009";
        PlotOrientation po = PlotOrientation.VERTICAL;
        JFreeChart chart = ChartFactory.createStackedBarChart(title, "Month", "Amount", dataset, po, true, true,
                true);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setForegroundAlpha(0.5f);
        BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null);
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage chartImage = new AImage("Stacked Bar Chart", bytes);

        Image img = new Image();
        img.setContent(chartImage);
        img.setParent(div_chartArea);

    } else {

        div_chartArea.getChildren().clear();

        Label label = new Label();
        label.setValue("This customer have no data for showing in a chart!");

        label.setParent(div_chartArea);

    }
}

From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java

/**
 * onClick button Stacked Bar 3D Chart. <br>
 * /*w  w  w  .j  a  v a  2s.c  o  m*/
 * @param event
 * @throws IOException
 */
public void onClick$button_CustomerChart_StackedBar3D(Event event) throws InterruptedException, IOException {
    // logger.debug(event.toString());

    div_chartArea.getChildren().clear();

    // get the customer ID for which we want show a chart
    long kunId = getCustomer().getId();

    // get a list of data
    List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId);

    if (kunAmountList.size() > 0) {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        for (ChartData chartData : kunAmountList) {

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(chartData.getChartKunInvoiceDate());

            int month = calendar.get(Calendar.MONTH) + 1;
            int year = calendar.get(Calendar.YEAR);
            String key = String.valueOf(month) + "/" + String.valueOf(year);

            BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3);
            String amount = String.valueOf(bd.doubleValue());

            // fill the data
            dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), key + " " + amount,
                    key + " " + amount);
        }

        String title = "Monthly amount for year 2009";
        PlotOrientation po = PlotOrientation.VERTICAL;
        JFreeChart chart = ChartFactory.createStackedBarChart3D(title, "Month", "Amount", dataset, po, true,
                true, true);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setForegroundAlpha(0.5f);
        BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null);
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage chartImage = new AImage("Stacked Bar Chart 3D", bytes);

        Image img = new Image();
        img.setContent(chartImage);
        img.setParent(div_chartArea);

    } else {

        div_chartArea.getChildren().clear();

        Label label = new Label();
        label.setValue("This customer have no data for showing in a chart!");

        label.setParent(div_chartArea);

    }
}

From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java

/**
 * onClick button Line Bar Chart. <br>
 * //  w  ww.  ja  v  a 2s  . c o m
 * @param event
 * @throws IOException
 */
public void onClick$button_CustomerChart_LineBar(Event event) throws InterruptedException, IOException {
    // logger.debug(event.toString());

    div_chartArea.getChildren().clear();

    // get the customer ID for which we want show a chart
    long kunId = getCustomer().getId();

    // get a list of data
    List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId);

    if (kunAmountList.size() > 0) {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        for (ChartData chartData : kunAmountList) {

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(chartData.getChartKunInvoiceDate());

            int month = calendar.get(Calendar.MONTH) + 1;
            int year = calendar.get(Calendar.YEAR);
            String key = String.valueOf(month) + "/" + String.valueOf(year);

            BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3);
            String amount = String.valueOf(bd.doubleValue());

            // fill the data
            dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), "2009",
                    key + " " + amount);
        }

        String title = "Monthly amount for year 2009";
        PlotOrientation po = PlotOrientation.VERTICAL;
        JFreeChart chart = ChartFactory.createLineChart(title, "Month", "Amount", dataset, po, true, true,
                true);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setForegroundAlpha(0.5f);
        BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null);
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage chartImage = new AImage("Line Bar Chart", bytes);

        Image img = new Image();
        img.setContent(chartImage);
        img.setParent(div_chartArea);

    } else {

        div_chartArea.getChildren().clear();

        Label label = new Label();
        label.setValue("This customer have no data for showing in a chart!");

        label.setParent(div_chartArea);

    }
}

From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java

/**
 * onClick button Line Bar 3D Chart. <br>
 * //from w  w  w.  j a v a2s. co m
 * @param event
 * @throws IOException
 */
public void onClick$button_CustomerChart_LineBar3D(Event event) throws InterruptedException, IOException {
    // logger.debug(event.toString());

    div_chartArea.getChildren().clear();

    // get the customer ID for which we want show a chart
    long kunId = getCustomer().getId();

    // get a list of data
    List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId);

    if (kunAmountList.size() > 0) {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        for (ChartData chartData : kunAmountList) {

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(chartData.getChartKunInvoiceDate());

            int month = calendar.get(Calendar.MONTH) + 1;
            int year = calendar.get(Calendar.YEAR);
            String key = String.valueOf(month) + "/" + String.valueOf(year);

            BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3);
            String amount = String.valueOf(bd.doubleValue());

            // fill the data
            dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), "2009",
                    key + " " + amount);
        }

        String title = "Monthly amount for year 2009";
        PlotOrientation po = PlotOrientation.VERTICAL;
        JFreeChart chart = ChartFactory.createLineChart3D(title, "Month", "Amount", dataset, po, true, true,
                true);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setForegroundAlpha(0.5f);
        BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null);
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage chartImage = new AImage("Line Bar Chart 3D", bytes);

        Image img = new Image();
        img.setContent(chartImage);
        img.setParent(div_chartArea);

    } else {

        div_chartArea.getChildren().clear();

        Label label = new Label();
        label.setValue("This customer have no data for showing in a chart!");

        label.setParent(div_chartArea);

    }
}