コード例 #1
1
 private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createBarChart(
           "Bar Chart Demo 1",
           "Category",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setDomainGridlinesVisible(true);
   categoryplot.setRangeCrosshairVisible(true);
   categoryplot.setRangeCrosshairPaint(Color.blue);
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
   barrenderer.setDrawBarOutline(false);
   GradientPaint gradientpaint =
       new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
   GradientPaint gradientpaint1 =
       new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
   GradientPaint gradientpaint2 =
       new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
   barrenderer.setSeriesPaint(0, gradientpaint);
   barrenderer.setSeriesPaint(1, gradientpaint1);
   barrenderer.setSeriesPaint(2, gradientpaint2);
   barrenderer.setLegendItemToolTipGenerator(
       new StandardCategorySeriesLabelGenerator("Tooltip: {0}"));
   CategoryAxis categoryaxis = categoryplot.getDomainAxis();
   categoryaxis.setCategoryLabelPositions(
       CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D));
   return jfreechart;
 }
コード例 #2
0
 /**
  * Returns a range axis for a plot.
  *
  * @param plot the plot.
  * @param index the axis index (<code>null</code> for the primary axis).
  * @return A range axis.
  */
 protected ValueAxis getRangeAxis(CategoryPlot plot, int index) {
   ValueAxis result = plot.getRangeAxis(index);
   if (result == null) {
     result = plot.getRangeAxis();
   }
   return result;
 }
コード例 #3
0
    /** Draws a chart into {@link JFreeChart}. */
    public JFreeChart createChart() {
      final JFreeChart chart =
          ChartFactory.createLineChart(
              null, // chart title
              null, // unused
              null, // range axis label
              dataset, // data
              PlotOrientation.VERTICAL, // orientation
              true, // include legend
              true, // tooltips
              false // urls
              );

      chart.setBackgroundPaint(Color.white);
      chart.getLegend().setItemFont(CHART_FONT);

      final CategoryPlot plot = chart.getCategoryPlot();
      configurePlot(plot);

      configureRangeAxis((NumberAxis) plot.getRangeAxis());

      crop(plot);

      return chart;
    }
コード例 #4
0
    @Override
    public void customize(JFreeChart chart, ReportParameters reportParameters) {

      BarRenderer barRenderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
      // barRenderer.setBaseSeriesVisible(false);//QUITA LAS BARRAS
      // barRenderer.setBaseSeriesVisibleInLegend(false);
      // barRenderer.setDrawBarOutline(false);
      barRenderer.setShadowVisible(false);
      barRenderer.setBarPainter(new CustomBarPainter());
      barRenderer.setItemMargin(0); // QUITA ESPACIOS ENTRE BARRA Y BARRA

      CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis();
      domainAxis.setUpperMargin(0);
      domainAxis.setLowerMargin(0);
      domainAxis.setCategoryMargin(0);
      domainAxis.setAxisLineVisible(false); // este es util

      Plot plot = chart.getPlot();
      // plot.setOutlineVisible(false);
      plot.setInsets(new RectangleInsets(0, 0, 0, 0)); // este sera util

      CategoryPlot categoryPlot = chart.getCategoryPlot();
      categoryPlot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
      // FAFO6categoryPlot.setRangeGridlinePaint(Color.WHITE);
      categoryPlot.setDomainGridlinesVisible(false);
      // FAFO5categoryPlot.setRangeGridlinesVisible(false);
      // categoryPlot.setBackgroundPaint(Color.white);
      categoryPlot.setOutlineVisible(false);

      ValueAxis valueAsix = categoryPlot.getRangeAxis();
      valueAsix.setAxisLineVisible(false); // este es muy util
      valueAsix.setRange(0, objDatosReporte.getIntMaxRango());
      valueAsix.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // este es muy util
    }
コード例 #5
0
ファイル: BarChart3DDemo.java プロジェクト: Rembau/media
  public static void main(String[] args) throws IOException {
    JFreeChart chart =
        ChartFactory.createBarChart3D(
            "图书销量统计图",
            "图书", // 目录轴的显示标签
            "销量", // 数值轴的显示标签
            getDataSet(),
            PlotOrientation.VERTICAL, // 设置图表方向
            false,
            false,
            false);

    // 设置标题
    chart.setTitle(new TextTitle("图书销量统计图", new Font("黑体", Font.ITALIC, 22)));
    // 设置图表部分
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryAxis categoryAxis = plot.getDomainAxis(); // 取得横轴
    categoryAxis.setLabelFont(new Font("宋体", Font.BOLD, 22)); // 设置横轴显示标签的字体
    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 分类标签以45度倾斜
    categoryAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 18)); // 分类标签字体

    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); // 取得纵轴
    numberAxis.setLabelFont(new Font("宋体", Font.BOLD, 42)); // 设置纵轴显示标签字体
    FileOutputStream fos = null;
    fos = new FileOutputStream("book1.jpg");
    ChartUtilities.writeChartAsJPEG(fos, 1, chart, 800, 600, null);

    fos.close();
  }
コード例 #6
0
 private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createLineChart(
           "Statistical Line Chart Demo 1",
           "Type",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   jfreechart.setBackgroundPaint(Color.white);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setBackgroundPaint(Color.lightGray);
   categoryplot.setRangeGridlinePaint(Color.white);
   CategoryAxis categoryaxis = categoryplot.getDomainAxis();
   categoryaxis.setUpperMargin(0.0D);
   categoryaxis.setLowerMargin(0.0D);
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   numberaxis.setAutoRangeIncludesZero(true);
   StatisticalLineAndShapeRenderer statisticallineandshaperenderer =
       new StatisticalLineAndShapeRenderer(true, false);
   statisticallineandshaperenderer.setUseSeriesOffset(true);
   categoryplot.setRenderer(statisticallineandshaperenderer);
   return jfreechart;
 }
コード例 #7
0
  /** Replaces the chart's dataset and then checks that the new dataset is OK. */
  public void testReplaceDataset() {

    // create a dataset...
    Number[][] data =
        new Integer[][] {
          {new Integer(-30), new Integer(-20)},
          {new Integer(-10), new Integer(10)},
          {new Integer(20), new Integer(30)}
        };

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue(
        "Expecting the lower bound of the range to be around -30: " + range.getLowerBound(),
        range.getLowerBound() <= -30);
    assertTrue(
        "Expecting the upper bound of the range to be around 30: " + range.getUpperBound(),
        range.getUpperBound() >= 30);
  }
コード例 #8
0
  public void loadDataToGrafik() throws IOException {
    DefaultCategoryDataset dataset = (DefaultCategoryDataset) this.generateData();
    chart =
        ChartFactory.createBarChart(
            "Statistik Pendidikan Dosen",
            "Prodi",
            "Jumlah Dosen",
            dataset,
            PlotOrientation.HORIZONTAL,
            true,
            true,
            false);
    chart.setBackgroundPaint(new Color(0xCC, 0xFF, 0xCC));

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final CategoryItemRenderer renderer1 = plot.getRenderer();
    renderer1.setSeriesPaint(0, Color.red);
    renderer1.setSeriesPaint(1, Color.yellow);
    renderer1.setSeriesPaint(2, Color.green);
    BarRenderer br = (BarRenderer) renderer1;
    br.setShadowVisible(false);

    br.setShadowVisible(false);
    BufferedImage bi = chart.createBufferedImage(900, 1500, BufferedImage.TRANSLUCENT, null);
    byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);
    AImage image = new AImage("Bar Chart", bytes);
    chartImg.setContent(image);
    btnExport.setDisabled(false);
  }
コード例 #9
0
 private void saveChart(final DefaultCategoryDataset dataset) throws IOException {
   final JFreeChart chart =
       ChartFactory.createBarChart(
           "HtmlUnit implemented properties and methods for " + browserVersion_.getNickname(),
           "Objects",
           "Count",
           dataset,
           PlotOrientation.HORIZONTAL,
           true,
           true,
           false);
   final CategoryPlot plot = (CategoryPlot) chart.getPlot();
   final NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   final LayeredBarRenderer renderer = new LayeredBarRenderer();
   plot.setRenderer(renderer);
   plot.setRowRenderingOrder(SortOrder.DESCENDING);
   renderer.setSeriesPaint(0, new GradientPaint(0, 0, Color.green, 0, 0, new Color(0, 64, 0)));
   renderer.setSeriesPaint(1, new GradientPaint(0, 0, Color.blue, 0, 0, new Color(0, 0, 64)));
   renderer.setSeriesPaint(2, new GradientPaint(0, 0, Color.red, 0, 0, new Color(64, 0, 0)));
   ImageIO.write(
       chart.createBufferedImage(1200, 2400),
       "png",
       new File(
           getArtifactsDirectory() + "/properties-" + browserVersion_.getNickname() + ".png"));
 }
コード例 #10
0
 private static JFreeChart createChart(CategoryDataset paramCategoryDataset) {
   JFreeChart localJFreeChart =
       ChartFactory.createAreaChart(
           "Area Chart",
           "Category",
           "Value",
           paramCategoryDataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   localJFreeChart.setBackgroundPaint(Color.white);
   TextTitle localTextTitle =
       new TextTitle(
           "An area chart demonstration.  We use this subtitle as an example of what happens when you get a really long title or subtitle.");
   localTextTitle.setPosition(RectangleEdge.TOP);
   localTextTitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05D, 0.05D, 0.05D, 0.05D));
   localTextTitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
   localJFreeChart.addSubtitle(localTextTitle);
   CategoryPlot localCategoryPlot = (CategoryPlot) localJFreeChart.getPlot();
   localCategoryPlot.setForegroundAlpha(0.5F);
   localCategoryPlot.setDomainGridlinesVisible(true);
   CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();
   localCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
   localCategoryAxis.setLowerMargin(0.0D);
   localCategoryAxis.setUpperMargin(0.0D);
   localCategoryAxis.addCategoryLabelToolTip("Type 1", "The first type.");
   localCategoryAxis.addCategoryLabelToolTip("Type 2", "The second type.");
   localCategoryAxis.addCategoryLabelToolTip("Type 3", "The third type.");
   NumberAxis localNumberAxis = (NumberAxis) localCategoryPlot.getRangeAxis();
   localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   localNumberAxis.setLabelAngle(0.0D);
   ChartUtilities.applyCurrentTheme(localJFreeChart);
   return localJFreeChart;
 }
コード例 #11
0
ファイル: ChartHelper.java プロジェクト: delving/sip-creator
 private static JFreeChart finishBarChart(JFreeChart chart, Color... colors) {
   CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
   categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
   categoryplot.setRangePannable(true);
   if (colors.length > 0) categoryplot.setRenderer(new CustomRenderer(colors));
   BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
   barrenderer.setItemLabelAnchorOffset(9D);
   barrenderer.setBaseItemLabelsVisible(true);
   barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
   barrenderer.setMaximumBarWidth(0.05);
   barrenderer.setItemMargin(0.03D);
   ItemLabelPosition itemlabelposition =
       new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT, -1.5707963267948966D);
   barrenderer.setBasePositiveItemLabelPosition(itemlabelposition);
   ItemLabelPosition itemlabelposition1 =
       new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT, -1.5707963267948966D);
   barrenderer.setPositiveItemLabelPositionFallback(itemlabelposition1);
   CategoryAxis categoryaxis = categoryplot.getDomainAxis();
   categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
   categoryaxis.setCategoryMargin(0.25D);
   categoryaxis.setUpperMargin(0.02D);
   categoryaxis.setLowerMargin(0.02D);
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   numberaxis.setUpperMargin(0.10000000000000001D);
   ChartUtilities.applyCurrentTheme(chart);
   return chart;
 }
コード例 #12
0
 private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createStackedBarChart3D(
           "Stacked Bar Chart 3D Demo 2",
           "Category",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setNumberFormatOverride(new DecimalFormat("0.0%"));
   StackedBarRenderer3D stackedbarrenderer3d = (StackedBarRenderer3D) categoryplot.getRenderer();
   stackedbarrenderer3d.setRenderAsPercentages(true);
   stackedbarrenderer3d.setDrawBarOutline(false);
   stackedbarrenderer3d.setBaseItemLabelGenerator(
       new StandardCategoryItemLabelGenerator(
           "{3}", NumberFormat.getIntegerInstance(), new DecimalFormat("0.0%")));
   stackedbarrenderer3d.setBaseItemLabelsVisible(true);
   stackedbarrenderer3d.setBasePositiveItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
   stackedbarrenderer3d.setBaseNegativeItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
   return jfreechart;
 }
コード例 #13
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private static JFreeChart createchart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "Bar Chart Demo 1", // chart
            // title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // 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 = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // ******************************************************************
    // More than 150 demo applications are included with the JFreeChart
    // Developer Guide...for more information, see:
    //
    // > http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

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

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    // renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
コード例 #14
0
ファイル: BarDemo28.java プロジェクト: yangyixiaof/gitcrawler
 /**
  * 更新图表显示
  *
  * @param chart
  */
 private void updatePlot(JFreeChart chart) {
   // 图表
   CategoryPlot categoryPlot = chart.getCategoryPlot();
   // y轴
   ValueAxis valueAxis = categoryPlot.getRangeAxis();
   // Y轴数据范围
   valueAxis.setRangeAboutValue(200, 1000);
 }
コード例 #15
0
ファイル: NumberAxisTest.java プロジェクト: Droikojan/KATA4
 /**
  * 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);
 }
コード例 #16
0
ファイル: LineChart.java プロジェクト: RainerJava/inventory
  private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart =
        ChartFactory.createLineChart(
            "Daily Stock Report", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    // customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesStroke(
        0,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {10.0f, 6.0f},
            0.0f));
    renderer.setSeriesStroke(
        1,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {6.0f, 6.0f},
            0.0f));
    renderer.setSeriesStroke(
        2,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {2.0f, 6.0f},
            0.0f));
    return chart;
  }
コード例 #17
0
ファイル: LineChartGen.java プロジェクト: richiewang/caipiao
  public JFreeChart createChart(int size) {
    CategoryDataset paramCategoryDataset = createDataset(size);
    // 创建主题样式
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    // 设置标题字体
    standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
    // 设置图例的字体
    standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 12));
    // 设置轴向的字体
    standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 12));
    // 应用主题样式
    ChartFactory.setChartTheme(standardChartTheme);
    JFreeChart localJFreeChart =
        ChartFactory.createLineChart(
            title, "期号", yTitle, paramCategoryDataset, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot localCategoryPlot = (CategoryPlot) localJFreeChart.getPlot();
    //		SymbolAxis localSymbolAxis = new SymbolAxis("个数", new String[] {
    //				"0", "1", "2", "3", "4", "5", "6" });
    //		localCategoryPlot.setRangeAxis(localSymbolAxis);
    ChartUtilities.applyCurrentTheme(localJFreeChart);
    LineAndShapeRenderer xyitem = (LineAndShapeRenderer) localCategoryPlot.getRenderer();
    CategoryPlot plot = (CategoryPlot) localJFreeChart.getPlot();
    // 设置网格背景颜色
    plot.setBackgroundPaint(Color.white);
    // 设置网格竖线颜色
    plot.setDomainGridlinePaint(Color.black);
    // 设置网格横线颜色
    plot.setRangeGridlinePaint(Color.black);
    // 设置曲线图与xy轴的距离
    plot.setAxisOffset(new RectangleInsets(0D, 0D, 0D, 0D));

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);
    if ("和值".equals(type)) {
      rangeAxis.setLowerBound(70);
      rangeAxis.setTickUnit(new NumberTickUnit(10));
    } else {
      rangeAxis.setLowerBound(0);
      rangeAxis.setTickUnit(new NumberTickUnit(1));
    }
    //		rangeAxis.setUpperMargin(0.20);
    // 设置曲线显示各数据点的值
    xyitem.setBaseItemLabelsVisible(true);
    xyitem.setBasePositiveItemLabelPosition(
        new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    xyitem.setSeriesStroke(0, new BasicStroke(1.5F));
    xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
    xyitem.setSeriesShapesVisible(0, true);
    plot.setRenderer(xyitem);
    return localJFreeChart;
  }
コード例 #18
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);
 }
コード例 #19
0
  /**
   * Method returns a constructed, fully customised chart.
   *
   * @param dataset - dataset from the de-serialized Statistics object
   * @return JFreeChart chart
   */
  private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "Time taken/Cells covered Performance", // Title of the chart
            "", // X Axis label
            "Time taken", // Y axis label
            dataset, // Data used for the chart
            PlotOrientation.VERTICAL, // Orientation of the chart to be drawn
            false, // Legend
            true, // Tooltips
            false // URL
            );

    // Display an additional label undeneath the bar chart to tell the user to hover over the bar
    // chart to see more deatils
    TextTitle legendText = new TextTitle("* Hover over the bar to see the cells covered.");
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);

    // Background for the chart
    chart.setBackgroundPaint(Color.white);

    // Store reference to the plot to customise it
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // Y axis should display integers only (so that the time taken is given in second integers)
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // Set the colours for the graphs
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));

    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    // Set up the X axis so that the title appears diagonal
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    return chart;
  }
コード例 #20
0
  @Override
  protected JFreeChart createGraph() {
    final JFreeChart chart =
        ChartFactory.createLineChart(
            null, // chart title
            null, // unused
            yLabel, // range axis label
            categoryDataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );

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

    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerBound(0);
    rangeAxis.setAutoRange(true);

    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2.0f));
    ColorPalette.apply(renderer);

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));

    return chart;
  }
  /**
   * Erstellt ein Stabdiagramm aus den Parametern.
   *
   * @param dataset Datenset
   * @param titel Titel
   * @return {@link JFreeChart}
   */
  protected JFreeChart erstelleDiagramm(
      CategoryDataset dataset,
      String titel,
      String reihenBeschriftung,
      String spaltenBeschriftung) {
    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart3D(
            titel,
            reihenBeschriftung,
            spaltenBeschriftung,
            dataset,
            PlotOrientation.VERTICAL,
            true,
            true,
            false);

    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.CENTER);
    t.setFont(new Font("Arial", Font.CENTER_BASELINE, 26));

    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    for (int i = 0; i < parteienListe.size(); i++) {
      if (parteienListe.get(i).getFarbe() != null) {
        GradientPaint gp =
            new GradientPaint(
                0.0f,
                0.0f,
                parteienListe.get(i).getFarbe(),
                0.0f,
                0.0f,
                new Color(parteienListe.get(i).getFarbe().getRGB()));
        renderer.setSeriesPaint(i, gp);
      }
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    return chart;
  }
コード例 #22
0
ファイル: GanttPlotter.java プロジェクト: preesm/preesm-apps
  /**
   * Creates a chart.
   *
   * @param dataset a dataset.
   * @return A chart.
   */
  private JFreeChart createChart(Gantt gantt, IntervalCategoryDataset dataset) {

    JFreeChart chart =
        ChartFactory.createGanttChart(
            "Solution Gantt", // title
            "Operators", // x-axis label
            "Time", // y-axis label
            null, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
            );

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    Paint p = getBackgroundColorGradient();
    chart.setBackgroundPaint(p);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setOrientation(PlotOrientation.HORIZONTAL);

    DateAxis xaxis = (DateAxis) plot.getRangeAxis();
    xaxis.setDateFormatOverride(new VertexDateFormat());
    xaxis.setPositiveArrowVisible(true);

    DefaultDrawingSupplier d = new DefaultDrawingSupplier();

    plot.setDrawingSupplier(d);
    GanttRenderer ren = new MyGanttRenderer();

    for (GanttElement element : gantt.getElementSet()) {
      ((MyGanttRenderer) ren).addColor(element.getTitle(), element.getColor());
    }

    ren.setSeriesItemLabelsVisible(0, false);
    ren.setSeriesVisibleInLegend(0, false);
    ren.setSeriesItemLabelGenerator(0, new IntervalCategoryItemLabelGenerator());
    ren.setSeriesToolTipGenerator(0, new MapperGanttToolTipGenerator());

    ren.setAutoPopulateSeriesShape(false);

    plot.setRenderer(ren);

    plot.setDataset(dataset);
    return chart;
  }
コード例 #23
0
ファイル: StackedBarChart.java プロジェクト: CaoAo/BeehiveZ
  // Pie Chart
  // //////////////////////////////////////////////////////////////////////////////
  protected JScrollPane getGraphPanel() {
    DefaultCategoryDataset dataset;
    if (absPerformance instanceof AbstractPerformance2D) {
      dataset = getDefaultCategoryDataset((AbstractPerformance2D) absPerformance);
    } else {
      dataset = getDefaultCategoryDataset(absPerformance);
    }

    PlotOrientation order = PlotOrientation.VERTICAL;
    if (orientationSort.getValue().equals("Horizontal")) {
      order = PlotOrientation.HORIZONTAL;
    }

    String strCategory = absPerformance.getItemName();
    if (absPerformance instanceof AbstractPerformance2D) {
      if (isItemA) {
        strCategory = ((AbstractPerformance2D) absPerformance).getSecondItemName();
      } else {
        strCategory = ((AbstractPerformance2D) absPerformance).getItemName();
      }
    }
    if (dimSort.getValue().equals("2D")) {
      chart =
          ChartFactory.createStackedBarChart(
              null, strCategory, "time", dataset, order, bLegend, true, false);
    } else if (dimSort.getValue().equals("3D")) {
      chart =
          ChartFactory.createStackedBarChart3D(
              null, strCategory, "time", dataset, order, bLegend, true, false);
    }

    // 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);

    chartPanel = new ChartPanel(chart, false);
    scrollPane = new JScrollPane(chartPanel);
    return scrollPane;
  }
コード例 #24
0
  public void createChart() {

    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report =
        ChartFactory.createStackedBarChart(
            this.datasetStrategy.getTitle(),
            this.datasetStrategy.getYAxisLabel(),
            this.datasetStrategy.getXAxisLabel(),
            categorydataset,
            PlotOrientation.HORIZONTAL,
            true,
            true,
            false);
    // report.setBackgroundPaint( Color.lightGray );
    report.setAntiAlias(false);
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CloverBarChartStrategy
        || datasetStrategy instanceof MultiCloverBarChartStrategy) {
      numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE);
      numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setItemLabelsVisible(true);
    stackedbarrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setItemLabelFont(
        StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD));
    int height =
        (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2)
            + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT
            + 10;
    if (height > ChartUtils.MINIMUM_HEIGHT) {
      super.setHeight(height);
    } else {
      super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
      stackedbarrenderer.setSeriesPaint(i, paints[i]);
    }
  }
コード例 #25
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "", // chart
            // title
            xLabel, // domain axis label
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // 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.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

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

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
コード例 #26
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private static JFreeChart createChart(CategoryDataset dataset) {

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

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    SubCategoryAxis axis = new SubCategoryAxis(null);
    axis.addSubCategory("S1");
    axis.addSubCategory("S2");
    axis.addSubCategory("S3");
    plot.setDomainAxis(axis);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

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

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    ChartUtilities.applyCurrentTheme(chart);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    return chart;
  }
コード例 #27
0
ファイル: First.java プロジェクト: RUB3XT0R/java_projects
  public static void createChart() {
    // criação do gráfico
    JFreeChart chart =
        ChartFactory.createLineChart(
            "Gráfico da Função: " + funcao, // titulo do gráfico
            "Resultados", // eixoy
            "Valores de Entrada", // eixox
            dataset, // base de dados
            PlotOrientation.VERTICAL,
            false, // legenda
            true, // dica, popup
            false // urls
            );
    // personalizando o gráfico

    TextTitle source =
        new TextTitle(
            "Atenção! Dependo do número de valores, pode ser que não apareça os mesmos no eixo horizontal.");
    source.setFont(new Font("SansSerif", Font.PLAIN, 10));
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    source.setBackgroundPaint(Color.WHITE);

    chart.addSubtitle(source);
    chart.setBackgroundPaint(Color.GRAY);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.BLACK);

    // desenha os pontos
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setLegendTextPaint(1, Color.WHITE);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    ChartFrame frame = new ChartFrame("Gráfico - Calculadora Função Atividade 2", chart);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
コード例 #28
0
ファイル: PopChart.java プロジェクト: argonium/workchart
  private JFreeChart getBarChart() {
    // Load the data, if necessary
    loadData();

    // Create the vertical bar chart
    final JFreeChart chart =
        ChartFactory.createBarChart(
            getTitle(),
            "",
            "",
            getCategoryDataset(),
            PlotOrientation.HORIZONTAL,
            false,
            true,
            false);
    final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    categoryplot.setRangePannable(true);
    categoryplot.setNoDataMessage("No data available");

    final BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setItemLabelAnchorOffset(9D);
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    // barrenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1} = {2}", new
    // DecimalFormat("0")));
    final CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryMargin(0.25D);

    categoryaxis.setUpperMargin(0.02D);
    categoryaxis.setLowerMargin(0.02D);
    final NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setUpperMargin(0.10000000000000001D);
    ChartUtilities.applyCurrentTheme(chart);

    //    if (useLegend())
    //    {
    //      // pieplot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})"));
    //      chart.getLegend().setPosition(RectangleEdge.RIGHT);
    //      // pieplot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("{0}:
    // {2}%"));
    //    }

    return chart;
  }
コード例 #29
0
ファイル: NumberAxisTest.java プロジェクト: Droikojan/KATA4
  /**
   * A check for the interaction between the 'autoRangeIncludesZero' flag and the base setting in
   * the BarRenderer.
   */
  @Test
  public void testAutoRange4() {
    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);
    BarRenderer br = (BarRenderer) plot.getRenderer();
    br.setIncludeBaseInRange(false);
    assertEquals(95.0, axis.getLowerBound(), EPSILON);
    assertEquals(205.0, axis.getUpperBound(), EPSILON);

    br.setIncludeBaseInRange(true);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(210.0, axis.getUpperBound(), EPSILON);

    axis.setAutoRangeIncludesZero(true);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(210.0, axis.getUpperBound(), EPSILON);

    br.setIncludeBaseInRange(true);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(210.0, axis.getUpperBound(), EPSILON);

    // now replacing the dataset should update the axis range...
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(900.0, "Row 1", "Column 1");
    dataset2.setValue(1000.0, "Row 1", "Column 2");
    plot.setDataset(dataset2);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(1050.0, axis.getUpperBound(), EPSILON);

    br.setIncludeBaseInRange(false);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(1050.0, axis.getUpperBound(), EPSILON);

    axis.setAutoRangeIncludesZero(false);
    assertEquals(895.0, axis.getLowerBound(), EPSILON);
    assertEquals(1005.0, axis.getUpperBound(), EPSILON);
  }
コード例 #30
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;
  }