示例#1
1
 /**
  * Updates the data set for both charts with the contents of the supplied Hashtable. The Hashtable
  * is expected to contain the following items:
  *
  * <ul>
  *   <li>down - The number of links currently in a down state
  *   <li>up - The number of links currently in an up state
  *   <li>unknown - The number of links currently in an unknown state
  * </ul>
  *
  * @param linkStats The hashtable containing the entries indicating current link statistics.
  */
 public void updateData(Hashtable<String, Integer> linkStats) {
   dpdCurrentData.insertValue(0, "Link Down", linkStats.get("down"));
   dpdCurrentData.insertValue(1, "Link Up", linkStats.get("up"));
   dpdCurrentData.insertValue(2, "Link State Unknown", linkStats.get("unknown"));
   dcdPreviousData.addValue(
       linkStats.get("down"), "Link Down", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("up"), "Link Up", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("unknown"),
       "Link State Unknown",
       Calendar.getInstance().getTime().toString());
 }
  public static void main(String[] args) throws Exception {
    DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset();
    line_chart_dataset.addValue(15, "schools", "1970");
    line_chart_dataset.addValue(30, "schools", "1980");
    line_chart_dataset.addValue(60, "schools", "1990");
    line_chart_dataset.addValue(120, "schools", "2000");
    line_chart_dataset.addValue(240, "schools", "2010");
    line_chart_dataset.addValue(300, "schools", "2014");

    JFreeChart lineChartObject =
        ChartFactory.createLineChart(
            "Schools Vs Years",
            "Year",
            "Schools Count",
            line_chart_dataset,
            PlotOrientation.VERTICAL,
            true,
            true,
            false);

    int width = 640; /* Width of the image */
    int height = 480; /* Height of the image */
    File lineChart = new File("LineChart.jpeg");
    ChartUtilities.saveChartAsJPEG(lineChart, lineChartObject, width, height);
  }
  public CategoryDataset generateData() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    List<Map> results = statistikPendidikanDosenDAO.getStatistikPendidikan();
    String[] jenjangs = {"S1", "S2", "S3"};

    for (Map prodi : statistikPendidikanDosenDAO.getProdi()) {
      String kodeProdi = "160" + prodi.get("Kd_prg").toString() + "0";
      for (String jenjang : jenjangs) {
        Map map = new HashMap();
        int pendidikan = 0;
        for (Map data : results) {
          if (kodeProdi.equalsIgnoreCase(data.get("kodeUnit").toString())) {
            if (data.get("Nm_jenjang").toString().equals(jenjang.toString())) {
              pendidikan++;
            }
          }
        }
        map.put("prodi", prodi.get("Nama_prg"));
        map.put("pendidikan", jenjang.toString());
        map.put("jumlah", pendidikan);
        dataset.addValue(
            Integer.valueOf(map.get("jumlah").toString()),
            map.get("pendidikan").toString(),
            map.get("prodi").toString());
      }
    }
    return dataset;
  }
示例#4
0
  /** Fills the chart with the content of the list of {@link HeapSegmentElement}. */
  private void showChart(ArrayList<HeapSegmentElement> list) {
    mAllocCountDataSet.clear();

    if (list != null) {
      String rowKey = "Alloc Count";

      long currentSize = -1;
      int currentCount = 0;
      for (HeapSegmentElement element : list) {
        if (element.getLength() != currentSize) {
          if (currentSize != -1) {
            ByteLong columnKey = new ByteLong(currentSize);
            mAllocCountDataSet.addValue(currentCount, rowKey, columnKey);
          }

          currentSize = element.getLength();
          currentCount = 1;
        } else {
          currentCount++;
        }
      }

      // add the last item
      if (currentSize != -1) {
        ByteLong columnKey = new ByteLong(currentSize);
        mAllocCountDataSet.addValue(currentCount, rowKey, columnKey);
      }
    }
  }
示例#5
0
  /**
   * Use for slider: limits the categories visualization from cat selected to cat
   * selected+numberscatsVisualization.
   *
   * @param dataset the dataset
   * @param categories the categories
   * @param catSelected the cat selected
   * @param numberCatsVisualization the number cats visualization
   * @return the dataset
   */
  public Dataset filterDataset(
      Dataset dataset, HashMap categories, int catSelected, int numberCatsVisualization) {
    logger.debug("IN");
    DefaultCategoryDataset catDataset = (DefaultCategoryDataset) dataset;

    int numCats = categories.size();
    Vector visCat = new Vector();
    // from the choice point to min(chose point+interval, end point)
    // int startPoint=((catSelected-1)*numberCatsVisualization)+1;
    int startPoint = catSelected;

    int endPoint;
    if ((startPoint + numberCatsVisualization - 1) <= (categories.size()))
      endPoint = startPoint + numberCatsVisualization - 1;
    else endPoint = categories.size();

    for (int i = (startPoint); i <= endPoint; i++) {
      String name = (String) categories.get(new Integer(i));
      visCat.add(name);
    }

    List columns = new Vector(catDataset.getColumnKeys());
    for (Iterator iterator = columns.iterator(); iterator.hasNext(); ) {
      String col = (String) iterator.next();
      if (!(visCat.contains(col))) {
        catDataset.removeColumn(col);
      }
    }
    logger.debug("OUT");

    return catDataset;
  }
示例#6
0
  public Dataset filterDatasetCatGroups(Dataset dataset, Vector groups) {
    logger.debug("IN");
    DefaultCategoryDataset catDataset = (DefaultCategoryDataset) dataset;

    // keeps track of wich series has to be shown
    currentCatGroups = groups;
    String catGroup = "";
    // List rowKeys=new Vector();

    // List rowKeys=new Vector(catDataset.getRowKeys());
    List colKeys = new Vector(catDataset.getColumnKeys());

    for (Iterator iterator = colKeys.iterator(); iterator.hasNext(); ) {
      String col = (String) iterator.next();
      // iterate on cols, get their group and see if it has to be kept
      catGroup = (String) catGroups.get(col);
      if (!(groups.contains(catGroup))) {
        catDataset.removeColumn(col);
        catGroupNames.remove(col);
      }
    }

    logger.debug("OUT");
    return catDataset;
  }
 private CategoryDataset createDataset() {
   DefaultCategoryDataset setCategory = new DefaultCategoryDataset();
   try {
     Part part = this.mainFrame.getCurrentPart();
     BookModel model = this.mainFrame.getBookModel();
     Session session = model.beginTransaction();
     StrandDAOImpl daoStrand = new StrandDAOImpl(session);
     List strands = daoStrand.findAll();
     SceneDAOImpl daoScene = new SceneDAOImpl(session);
     List scenes = daoScene.findDistinctDates(part);
     double d = 0.0D;
     Iterator iStrand = strands.iterator();
     while (iStrand.hasNext()) {
       Strand strand = (Strand) iStrand.next();
       Iterator iScene = scenes.iterator();
       while (iScene.hasNext()) {
         Date date = (Date) iScene.next();
         long l = daoStrand.countByDate(date, strand);
         setCategory.addValue(l, strand, date);
         d += l;
       }
     }
     model.commit();
     this.average = (d / (strands.size() + scenes.size()));
   } catch (Exception exc) {
     System.err.println("StrandsByDateChart.createDataset() Exception : " + exc.getMessage());
   }
   return setCategory;
 }
示例#8
0
  /** Some checks for the findRangeBounds() method. */
  @Test
  public void testFindRangeBounds() {
    BarRenderer r = new BarRenderer();
    assertNull(r.findRangeBounds(null));

    // an empty dataset should return a null range
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    assertNull(r.findRangeBounds(dataset));

    dataset.addValue(1.0, "R1", "C1");
    assertEquals(new Range(0.0, 1.0), r.findRangeBounds(dataset));
    r.setIncludeBaseInRange(false);
    assertEquals(new Range(1.0, 1.0), r.findRangeBounds(dataset));
    r.setIncludeBaseInRange(true);

    dataset.addValue(-2.0, "R1", "C2");
    assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));

    dataset.addValue(null, "R1", "C3");
    assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));

    dataset.addValue(-6.0, "R2", "C1");
    assertEquals(new Range(-6.0, 1.0), r.findRangeBounds(dataset));

    r.setSeriesVisible(1, Boolean.FALSE);
    assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));
  }
  /**
   * Creates a dataset.
   *
   * @return A dataset.
   */
  public static CategoryDataset createDataset2(String symbol) { // grafik volume
    DefaultCategoryDataset result = new DefaultCategoryDataset();

    String series1 = "Tahun";
    String series2 = "Tahun";

    try {
      Statement stat = koneksiDB.condb().createStatement();
      ResultSet rs =
          stat.executeQuery(
              "select year(reg_periksa.tgl_registrasi),count(year(reg_periksa.tgl_registrasi)) as jumlah "
                  + "from reg_periksa  "
                  + symbol
                  + " group by year(reg_periksa.tgl_registrasi)");
      while (rs.next()) {
        String tksbr = rs.getString(1) + "(" + rs.getString(2) + ")";
        double field1 = rs.getDouble(2);
        double field2 = rs.getDouble(2);

        result.addValue(field1, series1, tksbr);
        // result.addValue(field2, series2,tksbr);
      }
    } catch (SQLException e) {
      System.out.println("Error : " + e);
    }
    return result;
  }
 private JFreeChart formChart() {
   DefaultCategoryDataset data = new DefaultCategoryDataset();
   String dateString = request.getParameter("date");
   Date date = null;
   if (dateString != null && (!dateString.equals("null"))) {
     date = DayTransformer.transform(dateString);
   } else {
     date = new Date(System.currentTimeMillis());
   }
   String[][] storeSellingDis =
       saleperformanceManage.getStoreSellingDis(DayTransformer.transformToMonth(date));
   for (int i = 0; i < storeSellingDis.length; i++) {
     data.setValue(
         Double.parseDouble(storeSellingDis[i][1]), storeSellingDis[i][0], storeSellingDis[i][0]);
   }
   JFreeChart barChart =
       ChartFactory.createBarChart(
           "店铺销售分布图", "店铺名称", "销售额", data, PlotOrientation.VERTICAL, true, true, false);
   CategoryPlot plot = (CategoryPlot) barChart.getCategoryPlot();
   BarRenderer renderer = (BarRenderer) plot.getRenderer();
   // 显示条目标签
   renderer.setBaseItemLabelsVisible(true);
   // 设置条目标签生成器,在JFreeChart1.0.6之前可以通过renderer.setItemLabelGenerator(CategoryItemLabelGenerator
   // generator)方法实现,但是从版本1.0.6开始有下面方法代替
   renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
   // 设置条目标签显示的位置,outline表示在条目区域外,baseline_center表示基于基线且居中
   renderer.setBasePositiveItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
   barChart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 15)); // 设置引用标签字体
   barChart.getTitle().setFont(new Font("华文行楷", Font.BOLD, 32));
   return barChart;
 }
示例#11
0
  /*
   * Metodo que aplica o filtro
   */
  public static void Apply(BufferedImage image, String savePath) {
    // Chamada do metodo que gera os dados do histograma
    GetData(image);

    // Dataset que gera o grafico
    DefaultCategoryDataset ds = new DefaultCategoryDataset();

    // Loop que percorre o array de dados do histograma
    for (int k = 0; k < data.length; k++) {
      // Adiciona o valor ao dataset
      ds.setValue(data[k], "Imagem", Integer.toString(data[k]));
    }

    // Gera o grafico
    JFreeChart grafico =
        ChartFactory.createLineChart(
            "Histograma",
            "Tons de cinza",
            "Valor",
            ds,
            PlotOrientation.VERTICAL,
            true,
            true,
            false);

    // Salva o grafico em um arquivo de png
    try {
      OutputStream arquivo = new FileOutputStream(savePath);
      ChartUtilities.writeChartAsPNG(arquivo, grafico, 550, 400);
      arquivo.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  private JFreeChart getChart() {
    final Calendar now = Calendar.getInstance();
    final DefaultCategoryDataset sourceSet = new DefaultCategoryDataset();
    final boolean legend = false;
    final boolean tooltips = false;
    final boolean urls = false;

    final StringBuffer stringBuffer = new StringBuffer();
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {

        now.add(Calendar.DAY_OF_YEAR, 1);

        stringBuffer.setLength(0);

        sourceSet.addValue(
            new Integer(stringBuffer.append(i).append(j).toString()),
            String.valueOf(i),
            now.getTime());
      }
    }

    return ChartFactory.createBarChart(
        "fooTitle",
        "fooYLabel",
        "fooXLabel",
        sourceSet,
        PlotOrientation.VERTICAL,
        legend,
        tooltips,
        urls);
  }
  private void btnPictorialViewActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnPictorialViewActionPerformed
    // TODO add your handling code here:
    DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();

    for (Product product : supplier.getProductCatalog().getProductCatalog()) {
      categoryDataset.setValue(product.getSoldQuantity(), "Units", product.getProdName());
    }
    JFreeChart freeChart =
        ChartFactory.createBarChart(
            "Sales Report",
            "Product",
            "Units",
            categoryDataset,
            PlotOrientation.VERTICAL,
            false,
            true,
            false);

    CategoryPlot categoryPlot = freeChart.getCategoryPlot();
    categoryPlot.setRangeGridlinePaint(Color.BLACK);
    ChartFrame cf = new ChartFrame("Sales Report", freeChart);
    cf.setVisible(true);
    cf.setSize(450, 300);
  } // GEN-LAST:event_btnPictorialViewActionPerformed
示例#14
0
 private DefaultCategoryDataset createDataset(Histogram histogram) {
   DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
   for (Object key : histogram.keySet()) {
     dataSet.addValue(histogram.get(key), "", (Comparable) key);
   }
   return dataSet;
 }
示例#15
0
  protected void update() {
    // We have to rebuild the dataset from scratch (deleting and replacing it) because JFreeChart's
    // piechart facility doesn't have a way to move series.  Just like the histogram system: stupid
    // stupid stupid.

    SeriesAttributes[] sa = getSeriesAttributes();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int i = 0; i < sa.length; i++)
      if (sa[i].isPlotVisible()) {
        PieChartSeriesAttributes attributes = (PieChartSeriesAttributes) (sa[i]);

        Object[] elements = attributes.getElements();
        double[] values = null;
        String[] labels = null;
        if (elements != null) {
          HashMap map = convertIntoAmountsAndLabels(elements);
          labels = revisedLabels(map);
          values = amounts(map, labels);
        } else {
          values = attributes.getValues();
          labels = attributes.getLabels();
        }

        UniqueString seriesName = new UniqueString(attributes.getSeriesName());

        for (int j = 0; j < values.length; j++)
          dataset.addValue(values[j], labels[j], seriesName); // ugh
      }

    setSeriesDataset(dataset);
  }
示例#16
0
 private DefaultCategoryDataset createDataset() {
   DefaultCategoryDataset dataset = new DefaultCategoryDataset();
   for (String key : histogram.keySet()) {
     dataset.addValue(histogram.get(key), "", key);
   }
   return dataset;
 }
示例#17
0
  private CategoryDataset createDataset() {

    // row keys...
    final String series1 = "Closing Qty";
    final String series2 = "Issued Qty";
    final String series3 = "Received Qty";

    // column keys...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    String dbUrl = "jdbc:mysql://localhost/ventura_enterpride";
    String query = "Select * from daily_stock";

    try {
      Class.forName("com.mysql.jdbc.Driver");
      Connection con = DriverManager.getConnection(dbUrl, "root", "admin");
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery(query);

      while (rs.next()) {
        dataset.addValue(rs.getDouble(2), series1, rs.getDate(3) + "Item Id :" + rs.getInt(8));
        dataset.addValue(rs.getDouble(4), series2, rs.getDate(3) + "Item Id :" + rs.getInt(8));
        dataset.addValue(rs.getDouble(6), series3, rs.getDate(3) + "Item Id :" + rs.getInt(8));
      } // end while

      con.close();
    } // end try
    catch (Exception e) {
      e.printStackTrace();
    }
    return dataset;
  }
示例#18
0
  /**
   * @param response
   * @param type
   * @param alphaList
   * @param title
   * @param xTitle
   * @param yTitle
   */
  protected void createChart(
      final CollStatInfo csi,
      final Vector<Pair<String, Integer>> list,
      final String xTitle,
      final String yTitle) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (Pair<String, Integer> p : list) {
      dataset.addValue(p.second, p.first, "");
    }

    // if (StringUtils.isEmpty(csi.getInstName()))
    // {
    //    csi.setInstName(getProviderNameFromInstCode(csi.getProviderId()));
    // }

    JFreeChart chart =
        ChartFactory.createBarChart(
            csi.getTitle(), xTitle, yTitle, dataset, PlotOrientation.VERTICAL, true, true, false);

    // chart.getCategoryPlot().setRenderer(new CustomColorBarChartRenderer());

    chart.setBackgroundPaint(new Color(228, 243, 255));

    try {
      Integer hashCode = csi.hashCode();
      csi.setChartFileName(hashCode + ".png");
      DataOutputStream dos =
          new DataOutputStream(
              new FileOutputStream(new File("reports/charts/" + csi.getChartFileName())));
      ChartUtilities.writeChartAsPNG(dos, chart, 700, 600);

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
示例#19
0
  public Object produceDataset(Map arg0) throws DatasetProduceException {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    HashMap map = new HashMap();
    String sql1 =
        " select ww.he/10000 as he, ww.gl_opun_cod, c.code_value as   cityName "
            + " from ( "
            + "select  qq.he, qq.gl_opun_cod from ( "
            + "select sum(e.gl_dr_bal) he, substr(e.gl_opun_cod,0,3) gl_opun_cod  from "
            + "CRT_TOTAL_ACCOUNT e "
            + "where  e.gl_lg_no='79600000'  and DATA_DATE =(select max(DATA_DATE) from CRT_TOTAL_ACCOUNT) "
            + "group by substr(e.gl_opun_cod,0,3)"
            + "order by  sum(GL_DR_BAL) desc "
            + ") qq  where rownum <=10 )"
            + " ww,  ZCYM_CODE c where "
            + "ww.gl_opun_cod = substr(c.code_key,0,3) and c.code_name='省份' ";

    map.put("sql1", sql1);
    List list = chartUCC.queryDataList(map);
    double num = 0;
    HashMap map2 = null;
    if (list != null) {
      for (int i = 0; i < list.size(); i++) {
        map2 = (HashMap) list.get(i);
        BigDecimal big = (BigDecimal) map2.get("he");
        String cityName = (String) map2.get("cityName");
        if (big != null) {
          num = big.doubleValue();
        }
        dataset.addValue(num, "委托贷款余额", cityName);
      }
    }

    return dataset;
  }
  public NetflowTotalByIPChart(String title, String filename) {

    TotalsCSVReader reader =
        new TotalsCSVReader(filename, TotalsCSVReader.IP, TotalsCSVReader.OCTETS);
    HashMap<String, Integer> mappeddata = reader.getTotalsItems();
    Integer val;

    /* Create a simple Bar chart
     */
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (String protocol : mappeddata.keySet()) {
      val = mappeddata.get(protocol);
      dataset.setValue(val.intValue(), "Netflow", protocol);
    }

    JFreeChart chart =
        ChartFactory.createBarChart(
            "Total by IP",
            "IP Address",
            "Octets",
            dataset,
            PlotOrientation.VERTICAL,
            false,
            true,
            false);
    // create and display a frame...
    frame = new ChartFrame(title, chart);
    frame.pack();
  }
示例#21
0
 private static CategoryDataset getDataSet() {
   DefaultCategoryDataset dataset = new DefaultCategoryDataset();
   dataset.addValue(47000, "", "Spring2.0宝典");
   dataset.addValue(38000, "", "轻量级的J@EEE");
   dataset.addValue(31000, "", "JavaScript权威指南");
   dataset.addValue(25000, "", "Ajax In Action");
   return dataset;
 }
  public static DefaultCategoryDataset createDatasetForCriterionEvaluationCompareBarChart(
      List<Fragebogen> fragebogenList) {

    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();

    ArrayList<Bereich> bereiche =
        EvaluationHelper.getBereicheFromEvaluationHelper(fragebogenList.get(0).getBewertungen());

    for (Fragebogen f : fragebogenList) {

      double[] values = new double[bereiche.size()];
      int valCount = 0;
      for (Bereich bereich : bereiche) {
        valCount = 0;
        for (Bewertung bewertung : f.getBewertungen()) {
          if (bewertung.getItem() != null) {
            if (bereich.equals(bewertung.getItem().getBereich())) {
              if (!bewertung.getWert().isEmpty())
                values[bereiche.indexOf(bereich)] += Double.parseDouble(bewertung.getWert());
              valCount++;
            }
          }
        }
        if (valCount != 0) {
          values[bereiche.indexOf(bereich)] /= valCount;
        } else {
          values[bereiche.indexOf(bereich)] = 0;
        }
      }
      ArrayList<Handlungsfeld> hfList = new ArrayList<Handlungsfeld>();

      for (Bereich bereich : bereiche) {
        if (!hfList.contains(bereich.getHandlungsfeld())) {
          hfList.add(bereich.getHandlungsfeld());
        }
      }

      for (Handlungsfeld hf : hfList) {
        double ret = 0;
        int i = 0;
        for (Bereich bereich : bereiche) {
          if (bereich.getHandlungsfeld().equals(hf)) {
            ret += values[bereiche.indexOf(bereich)];
            i++;
          }
        }
        if (i > 0) {
          ret /= i;
        } else {
          ret = 0;
        }
        defaultcategorydataset.addValue(ret, f.getPerspektive().getName(), hf.getName());
      }
    }

    return defaultcategorydataset;
  }
 private static CategoryDataset createDataset() {
   String s = "S1";
   String s1 = "S2";
   String s2 = "S3";
   String s3 = "C1";
   String s4 = "C2";
   String s5 = "C3";
   String s6 = "C4";
   String s7 = "C5";
   DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
   defaultcategorydataset.addValue(1.0D, s, s3);
   defaultcategorydataset.addValue(4D, s, s4);
   defaultcategorydataset.addValue(3D, s, s5);
   defaultcategorydataset.addValue(5D, s, s6);
   defaultcategorydataset.addValue(5D, s, s7);
   defaultcategorydataset.addValue(5D, s1, s3);
   defaultcategorydataset.addValue(7D, s1, s4);
   defaultcategorydataset.addValue(6D, s1, s5);
   defaultcategorydataset.addValue(8D, s1, s6);
   defaultcategorydataset.addValue(4D, s1, s7);
   defaultcategorydataset.addValue(4D, s2, s3);
   defaultcategorydataset.addValue(3D, s2, s4);
   defaultcategorydataset.addValue(2D, s2, s5);
   defaultcategorydataset.addValue(3D, s2, s6);
   defaultcategorydataset.addValue(6D, s2, s7);
   return defaultcategorydataset;
 }
示例#24
0
 private static CategoryDataset createDataset() {
   String s = "First";
   String s1 = "Second";
   String s2 = "Third";
   String s3 = "Category 1";
   String s4 = "Category 2";
   String s5 = "Category 3";
   String s6 = "Category 4";
   String s7 = "Category 5";
   DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
   defaultcategorydataset.addValue(1.0D, s, s3);
   defaultcategorydataset.addValue(4D, s, s4);
   defaultcategorydataset.addValue(3D, s, s5);
   defaultcategorydataset.addValue(5D, s, s6);
   defaultcategorydataset.addValue(5D, s, s7);
   defaultcategorydataset.addValue(5D, s1, s3);
   defaultcategorydataset.addValue(7D, s1, s4);
   defaultcategorydataset.addValue(6D, s1, s5);
   defaultcategorydataset.addValue(8D, s1, s6);
   defaultcategorydataset.addValue(4D, s1, s7);
   defaultcategorydataset.addValue(4D, s2, s3);
   defaultcategorydataset.addValue(3D, s2, s4);
   defaultcategorydataset.addValue(2D, s2, s5);
   defaultcategorydataset.addValue(3D, s2, s6);
   defaultcategorydataset.addValue(6D, s2, s7);
   return defaultcategorydataset;
 }
  /**
   * Creates a dataset.
   *
   * @return A dataset.
   */
  public static CategoryDataset createDataset1() {
    DefaultCategoryDataset result = new DefaultCategoryDataset();
    String series1 = "First";
    String series2 = "Second";
    String type1 = "Type 1";
    String type2 = "Type 2";
    String type3 = "Type 3";
    String type4 = "Type 4";
    String type5 = "Type 5";
    String type6 = "Type 6";
    String type7 = "Type 7";
    String type8 = "Type 8";

    result.addValue(1.0, series1, type1);
    result.addValue(4.0, series1, type2);
    result.addValue(3.0, series1, type3);
    result.addValue(5.0, series1, type4);
    result.addValue(5.0, series1, type5);
    result.addValue(7.0, series1, type6);
    result.addValue(7.0, series1, type7);
    result.addValue(8.0, series1, type8);

    result.addValue(5.0, series2, type1);
    result.addValue(7.0, series2, type2);
    result.addValue(6.0, series2, type3);
    result.addValue(8.0, series2, type4);
    result.addValue(4.0, series2, type5);
    result.addValue(4.0, series2, type6);
    result.addValue(2.0, series2, type7);
    result.addValue(1.0, series2, type8);

    return result;
  }
示例#26
0
 private static CategoryDataset createDataset(ResultSet dt) throws Exception {
   DefaultCategoryDataset dataset = new DefaultCategoryDataset();
   ResultSet dx = dt;
   int x = 1;
   while (dx.next() && x < 5) {
     dataset.addValue(Integer.parseInt(dx.getString(2)), "", dx.getString(1));
     x++;
   }
   dx.close();
   return dataset;
 }
示例#27
0
 /**
  * A simple test for the auto-range calculation looking at a NumberAxis used as the range axis for
  * a CategoryPlot.
  */
 @Test
 public void testAutoRange1() {
   DefaultCategoryDataset dataset = new DefaultCategoryDataset();
   dataset.setValue(100.0, "Row 1", "Column 1");
   dataset.setValue(200.0, "Row 1", "Column 2");
   JFreeChart chart = ChartFactory.createBarChart("Test", "Categories", "Value", dataset);
   CategoryPlot plot = (CategoryPlot) chart.getPlot();
   NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   assertEquals(axis.getLowerBound(), 0.0, EPSILON);
   assertEquals(axis.getUpperBound(), 210.0, EPSILON);
 }
示例#28
0
  public JFreeChart getChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(5, "Sales", "2007");
    dataset.setValue(6, "Sales", "2008");

    JFreeChart chart =
        ChartFactory.createBarChart(
            "BarChart", "Year", "Sales", dataset, PlotOrientation.VERTICAL, false, true, true);

    return chart;
  }
示例#29
0
 /** Some checks for the getLegendItem() method. */
 @Test
 public void testGetLegendItem() {
   DefaultCategoryDataset dataset = new DefaultCategoryDataset();
   dataset.addValue(21.0, "R1", "C1");
   BarRenderer r = new BarRenderer();
   CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("x"), new NumberAxis("y"), r);
   /*JFreeChart chart =*/ new JFreeChart(plot);
   LegendItem li = r.getLegendItem(0, 0);
   assertNotNull(li);
   r.setSeriesVisibleInLegend(0, Boolean.FALSE);
   li = r.getLegendItem(0, 0);
   assertNull(li);
 }
示例#30
0
 /**
  * A simple test for the auto-range calculation looking at a NumberAxis used as the range axis for
  * a CategoryPlot. In this case, the 'autoRangeIncludesZero' flag is set to false.
  */
 public void testAutoRange2() {
   DefaultCategoryDataset dataset = new DefaultCategoryDataset();
   dataset.setValue(100.0, "Row 1", "Column 1");
   dataset.setValue(200.0, "Row 1", "Column 2");
   JFreeChart chart =
       ChartFactory.createBarChart(
           "Test", "Categories", "Value", dataset, PlotOrientation.VERTICAL, false, false, false);
   CategoryPlot plot = (CategoryPlot) chart.getPlot();
   NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   axis.setAutoRangeIncludesZero(false);
   assertEquals(axis.getLowerBound(), 95.0, EPSILON);
   assertEquals(axis.getUpperBound(), 205.0, EPSILON);
 }