[原]java生成图表

5 篇文章 0 订阅

主要jar:jfreechart.jar

	private JFreeChart chart;

	public JFreeChart getFoldlineGraph(double[][] data, String[] rowKeys, String[] columnKeys, boolean isline) {
		CategoryDataset dataset = getBarData(data, rowKeys, columnKeys);
		createTimeXYChar("单板测试通过率", "图例", "成功率", dataset, "", isline);
		return chart;
	}

	private CategoryDataset getBarData(double[][] data, String[] rowKeys, String[] columnKeys) {
		return DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
	}

private void createTimeXYChar(String chartTitle, String x, String y,
			CategoryDataset xyDataset, String charName, boolean isline) {
		chart = ChartFactory.createLineChart(chartTitle, x, y, xyDataset,
				PlotOrientation.VERTICAL, true, true, false);
		Font font00 = new Font("微软雅黑", Font.LAYOUT_NO_LIMIT_CONTEXT, 13);
		LegendTitle legend = chart.getLegend();
		legend.setItemFont(font00);// 设置注释字体
		chart.setTextAntiAlias(false);
		// 设置图标题的字体重新设置title
		Font font = new Font("微软雅黑", Font.LAYOUT_NO_LIMIT_CONTEXT, 15);
		TextTitle title = new TextTitle(chartTitle);
		title.setFont(font);
		chart.setTitle(title);
		CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
		// x轴分类轴网格是否可见
		categoryplot.setDomainGridlinesVisible(true);
		// y轴数据轴网格是否可见
		categoryplot.setRangeGridlinesVisible(true);
		categoryplot.setRangeGridlinePaint(Color.pink);// 虚线色彩
		categoryplot.setDomainGridlinePaint(Color.pink);// 虚线色彩
		categoryplot.setBackgroundPaint(Color.white);
		// 设置轴和面板之间的距离
		categoryplot.setAxisOffset(new RectangleInsets(0D, 0D, 0D, 0D));
		CategoryAxis domainAxis = categoryplot.getDomainAxis();
		domainAxis.setLabelFont(new Font("微软雅黑", Font.LAYOUT_NO_LIMIT_CONTEXT,
				13));// 轴标题
		domainAxis.setTickLabelFont(new Font("微软雅黑",
				Font.LAYOUT_NO_LIMIT_CONTEXT, 13));// 轴数值
		domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 横轴上的
		// 设置距离图片左端距离
		domainAxis.setLowerMargin(0);
		// 设置距离图片右端距离
		domainAxis.setUpperMargin(0);
		NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
		numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
		numberaxis.setAutoRangeIncludesZero(true);
		numberaxis.setLabelFont(new Font("微软雅黑", Font.LAYOUT_NO_LIMIT_CONTEXT,
				13));
		// 设置最高的一个值与图片顶端的距离
		numberaxis.setUpperMargin(0.15);
		// 设置最低的一个值与图片底端的距离
		// numberaxis.setLowerMargin(0.15);
		// 获得renderer
		LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot
				.getRenderer();
		lineandshaperenderer.setBaseShapesVisible(true); // series 点(即数据点)可见
		lineandshaperenderer.setBaseLinesVisible(isline); // series 点(即数据点)间有连线可见
		// 显示折点数据
		lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
		lineandshaperenderer.setBaseItemLabelsVisible(true);
	}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值