jfreechart柱形图详细属性设置

/** 
* plot 设置 
***/
 
//设置网格竖线颜色 
plot.setDomainGridlinePaint(Color.blue); 
plot.setDomainGridlinesVisible(true); 
//设置网格横线颜色 
plot.setRangeGridlinePaint(Color.blue); 

plot.setRangeGridlinesVisible(true); 
//图片背景色 
plot.setBackgroundPaint(Color.LIGHT_GRAY); 
plot.setOutlineVisible(true); 
//图边框颜色 
plot.setOutlinePaint(Color.magenta); 
//设置柱的透明度 
plot.setForegroundAlpha(1.0f); 
//将类型放到上面 
plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); 
//将默认放到左边的数值放到右边 
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); 
plot.setRenderer(renderer);//将修改后的属性值保存到图中 

/** 
* renderer设置 柱子相关属性设置 
*/
renderer.setBaseOutlinePaint(Color.ORANGE); //边框颜色 
renderer.setDrawBarOutline(true); 
renderer.setWallPaint(Color.gray);//设置墙体颜色 
renderer.setMaximumBarWidth(0.08); //设置柱子宽度 
renderer.setMinimumBarLength(0.1); //设置柱子高度 
renderer.setSeriesPaint(0,Color.ORANGE); //设置柱的颜色 
renderer.setItemMargin(0); //设置每个地区所包含的平行柱的之间距离 
//在柱子上显示相应信息 
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); 
renderer.setBaseItemLabelsVisible(true); 
renderer.setBaseItemLabelPaint(Color.BLACK);//设置数值颜色,默认黑色 
//搭配ItemLabelAnchor TextAnchor 这两项能达到不同的效果,但是ItemLabelAnchor最好选OUTSIDE,因为INSIDE显示不出来 
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT)); 
//下面可以进一步调整数值的位置,但是得根据ItemLabelAnchor选择情况. 
renderer.setItemLabelAnchorOffset(10); 

/** 
* rAxis设置 Y轴设置 

**/ 


//设置Y轴坐标上的文字 
rAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12)); 
//设置Y轴的标题文字 
rAxis.setLabelFont(new Font("黑体", Font.PLAIN, 12)); 
//Y轴取值范围(下面不能出现 rAxis.setAutoRange(true) 否则不起作用) 
rAxis.setRange(100, 600); 
// rAxis.setLowerBound(100); //Y轴以开始的最小值 
// rAxis.setUpperBound(600);//Y轴的最大值 
rAxis.setLabel("content");//Y轴内容 
rAxis.setLabelAngle(1.6);//标题内容显示角度(1.6时候水平) 
rAxis.setLabelPaint(Color.red);//标题内容颜色 
rAxis.setMinorTickMarksVisible(true);//标记线是否显示 
rAxis.setMinorTickCount(7);//节段中的刻度数 
rAxis.setMinorTickMarkInsideLength(3);//内刻度线向内长度 
rAxis.setMinorTickMarkOutsideLength(3);//内刻度记线向外长度 
rAxis.setTickMarkInsideLength(3);//外刻度线向内长度 
rAxis.setTickMarkPaint(Color.red);//刻度线颜色 
rAxis.setTickLabelsVisible(true);//刻度数值是否显示 
// 所有Y标记线是否显示(如果前面设置rAxis.setMinorTickMarksVisible(true); 则其照样显示) 
rAxis.setTickMarksVisible(true); 
rAxis.setAxisLinePaint(Color.red);//Y轴竖线颜色 
rAxis.setAxisLineVisible(true);//Y轴竖线是否显示 
//设置最高的一个 Item 与图片顶端的距离 (在设置rAxis.setRange(100, 600);情况下不起作用) 
rAxis.setUpperMargin(0.15); 
//设置最低的一个 Item 与图片底端的距离 
rAxis.setLowerMargin(0.15); 
rAxis.setAutoRange(true);//是否自动适应范围 
rAxis.setVisible(true);//Y轴内容是否显示 

//数据轴精度 
NumberAxis na = (NumberAxis) plot.getRangeAxis(); 
na.setAutoRangeIncludesZero(true); 
DecimalFormat df = new DecimalFormat("#0.000"); 
//数据轴数据标签的显示格式 
na.setNumberFormatOverride(df); 

/*** 
* domainAxis设置(x轴一些设置) 
**/
 

//设置X轴坐标上的文字 
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11)); 
//设置X轴的标题文字 
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12)); 
domainAxis.setLabel("");//X轴的标题内容 
domainAxis.setTickLabelPaint(Color.red);//X轴的标题文字颜色 
domainAxis.setTickLabelsVisible(true);//X轴的标题文字是否显示 
domainAxis.setAxisLinePaint(Color.red);//X轴横线颜色 
domainAxis.setTickMarksVisible(true);//标记线是否显示 
domainAxis.setTickMarkOutsideLength(3);//标记线向外长度 
domainAxis.setTickMarkInsideLength(3);//标记线向内长度 
domainAxis.setTickMarkPaint(Color.red);//标记线颜色 
domainAxis.setUpperMargin(0.2);//设置距离图片左端距离 
domainAxis.setLowerMargin(0.2); //设置距离图片右端距离 
//横轴上的 Lable 是否完整显示 
domainAxis.setMaximumCategoryLabelWidthRatio(0.6f); 
//横轴上的 Lable 45度倾斜 
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); 

/*----------设置消除字体的锯齿渲染(解决中文问题)--------------*/ 
chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, 
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); 
//底部汉字乱码的问题 
chart.getLegend().setItemFont(new Font("宋体",Font.PLAIN,12)); 
//设置标题字体 
TextTitle textTitle = chart.getTitle(); 
textTitle.setFont(new Font("黑体", Font.PLAIN, 20)); 
textTitle.setBackgroundPaint(Color.LIGHT_GRAY);//标题背景色 
textTitle.setPaint(Color.cyan);//标题字体颜色 
textTitle.setText("类型统计图");//标题内容 


CategoryPlot plot = chart.getCategoryPlot();//设置图的高级属性 
BarRenderer3D renderer = new BarRenderer3D();//3D属性修改 
CategoryAxis domainAxis = plot.getDomainAxis();//对X轴做操作 
ValueAxis rAxis = plot.getRangeAxis();//对Y轴做操作 

/**参数分别为:图表标题 ,目录轴的显示标签 ,数值轴的显示标签 ,数据集 ,是否生成URL链接 
图表方向:水平、垂直, 是否显示图例(对于简单的柱状图必须是false) ,是否生成工具 */ 

JFreeChart chart = ChartFactory.createBarChart3D("XXX统计图", "类型","数据额", dataset, PlotOrientation.VERTICAL, true, false, true); 
整体
 //设置距离图片左端距离 
      domainAxis.setUpperMargin(0.2); 
       //设置距离图片右端距离 
      domainAxis.setLowerMargin(0.2); 
          //数据轴精度 
       NumberAxis na = (NumberAxis) plot.getRangeAxis(); 
          na.setAutoRangeIncludesZero(true); 
      DecimalFormat df = new DecimalFormat("#0.000"); 
      //数据轴数据标签的显示格式 
      na.setNumberFormatOverride(df); 
          //设置柱的透明度 
      plot.setForegroundAlpha(1.0f); 
 //将类型放到上面 
plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); 
    //横轴上的 Lable 45度倾斜 
      domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); 
//将默认放到左边的数值放到右边 
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); 
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值