Package service

Source Code of service.XYGrafikPaneliDonenSinif

package service;

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.UIManager;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

public class XYGrafikPaneliDonenSinif {

  private DefaultCategoryDataset dataset;
  /**
   * Launch the application.
   */
  private DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
  private DefaultPieDataset dataset2;

  /**
   * Create the application.
   */

  public ChartPanel xyGrafigi(Double[] tutar, String barIsmi,
      String[] kategori, String yAxisAdi) {
    dataset1 = (DefaultCategoryDataset) createDataSet(tutar, barIsmi,
        kategori);
    JFreeChart chart = ChartFactory.createBarChart(
        "Günlere Göre Satış Grafiği", // chart title
        null, // domain axis label
        yAxisAdi, // range axis label
        dataset1, // data
        PlotOrientation.VERTICAL, true, // include legend
        true, // tooltips?
        false // URL generator? Not required...
        );
    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    ChartPanel cp = new ChartPanel(chart);
    cp.setBackground(UIManager.getColor("Button.shadow"));
    cp.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    return cp;
  }

  public ChartPanel pastaDilimi(Double[] tutar, String barIsmi,
      String[] kategori) {
    DefaultPieDataset dpd = createPieChartDataset(kategori, tutar);
    JFreeChart chart = ChartFactory.createPieChart(
        "Günlere Göre Satış Grafiği", dpd, true, true,
        false);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setNoDataMessage("İşlenecek Veri Yok");
    plot.setCircular(false);
    plot.setLabelGap(0.02);

    chart.setBackgroundPaint(new Color(255, 255, 255));
    ChartPanel cp = new ChartPanel(chart);
    cp.setBackground(UIManager.getColor("Button.shadow"));
    cp.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    return cp;
  }

  private DefaultPieDataset createPieChartDataset(String[] kategori,
      Double[] tutar) {

    dataset2 = new DefaultPieDataset();
    for (int i = 0; i < tutar.length; i++) {
      if (kategori[i] == null) {
        break;
      }
      dataset2.setValue(kategori[i], tutar[i]);
    }

    return dataset2;
  }

  private CategoryDataset createDataSet(Double[] tutar, String barIsmi,
      String[] kategori) {

    dataset = new DefaultCategoryDataset();
    for (int i = 0; i < kategori.length; i++) {
      if (kategori[i] == null) {
        break;
      }
      dataset.addValue(tutar[i], barIsmi, kategori[i]);

    }

    return dataset;

  }

  /**
   * Initialize the contents of the frame.
   */

TOP

Related Classes of service.XYGrafikPaneliDonenSinif

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.