JFreeChart图例设置

勇往直前123 2013-09-05 05:58:36



这是用JfreeChart画出来的图表,其中我用红框框标注出来的图例,太小了,我想让它变大,加粗,成矩形或正方形的小图例,改怎么改,急急急....求助。
...全文
908 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
baidu_35059031 2016-05-20
  • 打赏
  • 举报
回复
楼楼,请问你的双y轴线条如何颜色不重复呢,我最近也在画这个但是双y轴总是有颜色重复的线条!
cupsuccess 2014-05-04
  • 打赏
  • 举报
回复
麻烦问下楼主,怎么可以做到一条折线图显示折点一条折线图不显示?
勇往直前123 2013-10-17
  • 打赏
  • 举报
回复
其实,使用JFreeChart画图表的时候,图表的图例是根据图表中的图形而显示的,比如饼状图,他的图例是圆形的,柱状图,它的图例是方形的,折线图,它的图例就是线条。所以折线图想要方形的图例,JFreeChart的API是不提供直接修改图例的属性,除非你自己改写它的图例属性。
勇往直前123 2013-09-09
  • 打赏
  • 举报
回复
非常感谢“冬雪晶”的回答,可是我现在想改的只是图表下方的图例,而不是改图表
s478853630 2013-09-05
  • 打赏
  • 举报
回复
/**
	 * 柱状图
	 * @param dataset
	 * @param plot
	 * @param width
	 * @param height
	 * @throws Exception
	 */
	public void pillar(DefaultCategoryDataset dataset, PlotOrientation plot, Integer width, Integer height) throws Exception {
		JFreeChart chart = ChartFactory.createBarChart3D("", "", "", dataset, plot, true, true, true);
		CategoryPlot plot1 = chart.getCategoryPlot();//获得图表区域对象
		BarRenderer3D bar = (BarRenderer3D) plot1.getRenderer();
		bar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());//显示每个柱的数值
		bar.setBaseItemLabelsVisible(true); 
		bar.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
		bar.setItemLabelAnchorOffset(-12D);// 设置柱形图上的文字偏离值 
		if (height == 35) {
			height = 135;
			bar.setMaximumBarWidth(0.25); 
			bar.setItemMargin(0.000000005);
		}
		plot1.setRenderer(bar); 
		try {
			NumberAxis axis = (NumberAxis) plot1.getRangeAxis();// y轴精度
			axis.setAutoRangeIncludesZero(true);// 设置刻度必须从0开始 
			axis.setNumberFormatOverride(new DecimalFormat("#0"));
		} catch (Exception e) {}
		getResponse().setContentType("text/plain;charset=UTF-8");
		ChartUtilities.writeChartAsPNG(getResponse().getOutputStream(), chart, width, height);
	}
	
	/**
	 * 折线图
	 * @param dataset
	 * @param plot
	 * @param width
	 * @param height
	 * @throws Exception
	 */
	public void line(DefaultCategoryDataset dataset, PlotOrientation plot, Integer width, Integer height) throws Exception {
		JFreeChart chart = ChartFactory.createLineChart("", "", "", dataset, plot, true, true, true);
		CategoryPlot plot1 = chart.getCategoryPlot();//获得图表区域对象
		LineAndShapeRenderer renderer = new LineAndShapeRenderer();
		//renderer.setSeriesPaint(0, Color.BLUE);// 改变折线的颜色
		renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());//显示每个柱的数值
		renderer.setBaseItemLabelsVisible(true); 
		renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
		renderer.setItemLabelAnchorOffset(2D);// 设置柱形图上的文字偏离值 
		if (height == 35) {
			height = 135;
		}
		plot1.setRenderer(renderer);// 给折线加点
		try {
			NumberAxis axis = (NumberAxis) plot1.getRangeAxis();// y轴精度
			axis.setAutoRangeIncludesZero(true);// 设置刻度必须从0开始 
			axis.setNumberFormatOverride(new DecimalFormat("#0"));
		} catch (Exception e) {}
		getResponse().setContentType("text/plain;charset=UTF-8");
		ChartUtilities.writeChartAsPNG(getResponse().getOutputStream(), chart, width, height);
	}
	
	/**
	 * 饼图
	 * @param dataset
	 * @param width
	 * @param height
	 * @throws Exception
	 */
	public void round(DefaultPieDataset dataset, Integer width, Integer height) throws Exception {
		JFreeChart chart = ChartFactory.createPieChart("", dataset, true, true, true);
		PiePlot plot = (PiePlot) chart.getPlot(); 
		plot.setLabelLinkMargin(0.1d);
		plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00%")));
		getResponse().setContentType("text/plain;charset=UTF-8");
		ChartUtilities.writeChartAsPNG(getResponse().getOutputStream(), chart, width, height);
	}

81,115

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧