`
huanglppp
  • 浏览: 63285 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

JFreeChart圆柱图中文乱码

阅读更多
windins xp,jfreechart版本用的是:1.0.11,有些代码关系到业务,就不贴了。。。下面是返回chart的实例
.....
CategoryDataset categorydataset = defaultcategorydataset;
		JFreeChart jfreechart = ChartFactory.createBarChart("工序产量("+factoryName+")", // 图形标题名称
				"",// domain 轴 Lable这里先简单理解为横坐标Lable好了
				"", // range 轴 Lable这里也先简单理解为纵坐标Lable好了
				categorydataset, // dataset
				PlotOrientation.VERTICAL, // 垂直显示
				false, // legend?
				true, // tooltips?
				false); // URLs?
		jfreechart.setBackgroundPaint(Color.white); // 设定背景色为白色
		Font font = new Font("SimSun",10,20);
		TextTitle txtTitle =jfreechart.getTitle();
		txtTitle.setFont(font);
		CategoryPlot categoryplot = jfreechart.getCategoryPlot(); // 获得
		// plot:CategoryPlot!!
		categoryplot.setNoDataMessage("没有数据!");
		categoryplot.setBackgroundPaint(Color.lightGray); // 设定图表数据显示部分背景色
		categoryplot.setDomainGridlinePaint(Color.white); // 横坐标网格线白色
		categoryplot.setDomainGridlinesVisible(true); // 可见
		categoryplot.setRangeGridlinePaint(Color.white); // 纵坐标网格线白色
		
		// 下面两行使纵坐标的最小单位格为整数
		NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
		numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
		
		 Paint apaint[] = {
		             new Color(255,0,0),new Color(0,255,0), new Color(255,255,0)
		        };
		CustomRenderer customrenderer = new CustomRenderer(apaint,listMesKanBanItem);
        customrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        customrenderer.setBaseItemLabelsVisible(true);
        ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0D);
        customrenderer.setBasePositiveItemLabelPosition(itemlabelposition);
        customrenderer.setMaximumBarWidth(0.10000000000000001D);//设置圆柱图宽度
		// 注意这里是下嗍造型到BarRenderer!
        customrenderer.setDrawBarOutline(false); // Bar的外轮廓线不画
        categoryplot.setRenderer(customrenderer);
        		CategoryAxis categoryaxis = categoryplot.getDomainAxis(); // 横轴上的
		// Lable
		// 标准
		categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
		categoryaxis.setMaximumCategoryLabelWidthRatio(0.8F);
        categoryaxis.setLowerMargin(0.02D);
        categoryaxis.setUpperMargin(0.02D);
        categoryaxis.setLabelFont(font);
        ChartUtilities.applyCurrentTheme(jfreechart);
		return jfreechart;

运行后效果如下:

。。。标题和横纵上的都是乱码。。。请高手指点下
  • 大小: 21.2 KB
分享到:
评论
7 楼 feiyan35488 2011-06-07  
字体原因是 1.0.10以后的版本的默认字体 改为了一个不常用的字体,大家的电脑上都没有这个字体文件,于是就看到方块了。 将手动设置一下字体即可
6 楼 lanhongbo 2010-08-26  
47.        ChartUtilities.applyCurrentTheme(jfreechart);  
这句话去掉就好了 应该是里面设置了编码之类的东西
5 楼 xxqn 2009-04-05  
从1.0.11开始变化比较大,引入许多新东西,例如阴影,图形也更加漂亮了,其实我看应该这样标记版本号比较好1.1.1。
4 楼 lunzi 2008-12-21  
我也碰到了 确实是版本问题
3 楼 huanglppp 2008-11-20  
开始用的是jfreechart-1.0.11,现在该为jfreechart-1.0.10就OK了。。。
太新的版本有个时候不稳定
2 楼 moonfork 2008-11-20  
是什么版本的原因啊,能否详细说明点?
1 楼 huanglppp 2008-11-20  
前些天搞定。。。原来是版本的问题。。。。。非常的汗

相关推荐

Global site tag (gtag.js) - Google Analytics