Exemplo n.º 1
0
  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;
  }
Exemplo n.º 2
0
 protected void setDefaultCategoryItemRenderer() {
   // 获得renderer 注意这里是下嗍造型到lineandshaperenderer!!
   lineandshaperenderer = (LineAndShapeRenderer) categoryPlot.getRenderer();
   // 天蓝
   lineandshaperenderer.setSeriesPaint(0, new Color(41, 106, 232));
   // lineandshaperenderer.setSeriesPaint(1, new Color(255,0,255));//桃红2
   // lineandshaperenderer.setSeriesPaint(2, new Color(255,255,128));//黄色3
   // lineandshaperenderer.setSeriesPaint(3, new Color(0,255,255));//蓝4
   // lineandshaperenderer.setSeriesPaint(4, new Color(128,0,128));//紫5
   // lineandshaperenderer.setSeriesPaint(5, new Color(0,0,255));//墨绿6
   // lineandshaperenderer.setSeriesPaint(6, new Color(0,0,128));//蓝7
   // lineandshaperenderer.setSeriesPaint(7, new Color(0,204,255));//草绿
   // lineandshaperenderer.setSeriesPaint(8, new Color(192,192,192));//天蓝
   // lineandshaperenderer.setSeriesPaint(9, new Color(204,255,204));//天蓝
   // 点(即数据点)可见
   lineandshaperenderer.setBaseShapesVisible(true);
   // 显示折点数据
   lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
   // 显示折点数据
   lineandshaperenderer.setBaseItemLabelsVisible(true);
   // 折点数据字体
   lineandshaperenderer.setBaseItemLabelFont(FontUtil.getFont_verdana_Plain(12));
   // 折点数据显示位置
   ItemLabelPosition position =
       new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER);
   lineandshaperenderer.setBasePositiveItemLabelPosition(position);
   // 点(即数据点)间有连线可见
   lineandshaperenderer.setBaseLinesVisible(true);
   // 定义series为”First”的(即series1)点之间的连线 ,这里是虚线,默认是直线
   // lineandshaperenderer.setSeriesStroke(0, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 10F,
   // 6F }, 0.0F));
   // XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
   // xylineandshaperenderer.setSeriesLinesVisible(0, false); //第一个XYSeries数据点间连线不可见
   // xylineandshaperenderer.setSeriesShapesVisible(1, false); //第二个XYSeries数据点不可见
   // xyplot.setRenderer(xylineandshaperenderer);
 }