Exemplo n.º 1
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "Bar Chart Demo 8", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
            );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.15);

    // disable bar outlines...
    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
Exemplo n.º 2
0
  /**
   * 棒・折れ線・面チャート用ツールチップ設定メソッド
   *
   * @param doc XML文書(JFreeChart用XMLドキュメント)
   * @param renderer レンダラーオブジェクト
   */
  public void setToolTip(Document doc, CategoryItemRenderer renderer) {

    Element root = doc.getDocumentElement();
    Element chartInfo = (Element) root.getElementsByTagName("ChartInfo").item(0);
    String hasToolTip =
        chartInfo.getElementsByTagName("hasToolTip").item(0).getFirstChild().getNodeValue();

    // ツールチップ有り
    if ("1".equals(hasToolTip)) {
      renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }

    // ツールチップ無し
    else {
      // 何もしない(ツールチップ表示しない)
    }
  }