欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JFreeChart圆柱图中文乱码

程序员文章站 2022-04-28 12:43:15
...
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;

运行后效果如下:
[img]http://huanglppp.iteye.com/upload/attachment/49665/27c62ad7-0a9f-34cc-94c6-c14da7577b65.bmp[/img]
。。。标题和横纵上的都是乱码。。。请高手指点下
相关标签: jfreechart XP