Jfreechart生成曲线图、数据点

本文介绍如何利用JFreeChart库在Java中创建曲线图,并详细展示了生成数据点图标及显示数据值的关键代码,重点在于DefaultCategoryDataset数据集的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

生成此图中的数据点图标和显示数据值的主要代码就是下面这些,这里使用的是DefaultCategoryDataset数据集:

 

                CategoryPlot plot=chart.getCategoryPlot(); 
                plot.setBackgroundPaint(Color.WHITE);
                plot.setRangeGridlinePaint(Color.BLUE);
//纵坐标格线颜色
                plot.setDomainGridlinePaint(Color.BLACK);//横坐标格线颜色
                plot.setDomainGridlinesVisible(true);//显示横坐标格线
                plot.setRangeGridlinesVisible(true);//显示纵坐标格线
                
                            
                LineAndShapeRenderer renderer 
= (LineAndShapeRenderer)plot.getRenderer();
                DecimalFormat decimalformat1 
= new DecimalFormat("##.##");//数据点显示数据值的格式
                renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));
                                                  
//上面这句是设置数据项标签的生成器
                renderer.setItemLabelsVisible(true);//设置项标签显示
                renderer.setBaseItemLabelsVisible(true);//基本项标签显示
                         
//上面这几句就决定了数据点按照设定的格式显示数据值  
                renderer.setShapesFilled(Boolean.TRUE);//在数据点显示实心的小图标
                renderer.setShapesVisible(true);//设置显示小图标

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值