(5)Jfreechart环形图

1、环形效果图

这里写图片描述

2、详解

通过createRingChart创建环形图
JFreeChart chart5 = ChartFactory.createRingChart(“环形分布图测试”,
getPieOrRingChartDataSet(), true, true, Locale.CHINESE);
设置样式
chart.setBackgroundPaint(Color.white);
RingPlot ringplot = (RingPlot) chart.getPlot();
ringplot.setLabelBackgroundPaint(Color.WHITE);
//设置环形图的每个扇区的样式
ringplot.setSectionPaint(0, new Color(128, 100, 162));
ringplot.setSectionPaint(1, new Color(155, 187, 89));
ringplot.setSectionPaint(2, new Color(192, 80, 77));
// ringplot.setLabelLinksVisible(false);
// 设置饼状图和环形图的显示数字。0代表显示文字说明,1代表显示数字,2代表显示数字以百分比的方式如果多个结合{0}:{1}
ringplot.setLabelGenerator(new StandardPieSectionLabelGenerator(“{2}”));
ringplot.setSimpleLabels(true);
ringplot.setLabelBackgroundPaint(new Color(1.0F, 0.75F, 0.0F, 0.0F));
ringplot.setLabelFont(new Font(“sans-serif”, Font.PLAIN, 12));
ringplot.setLabelOutlinePaint(new Color(1.0F, 0.75F, 0.0F, 0.0F));
ringplot.setLabelPaint(Color.white);
ringplot.setLabelFont(new Font(“微软雅黑”, Font.PLAIN, 24));
ringplot.setLabelShadowPaint(new Color(1.0F, 0.75F, 0.0F, 0.0F));
TextTitle title = chart.getTitle();
title.setFont(new Font(“sans-serif”, Font.PLAIN, 24));
// 设置深度,即带颜色圆环的宽度
ringplot.setSectionDepth(0.5d);
// 设置环形图背景颜色
ringplot.setBackgroundPaint(Color.white);
设置数据集
private static PieDataset getPieOrRingChartDataSet() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue(“2.0分-3.0分”, new Double(10));
dataset.setValue(“3.0分-4.0分”, new Double(10));
dataset.setValue(“4.0分-5.0分”, new Double(80));
return dataset;
}
在main方法中执行
ChartFrame pieFrame = new ChartFrame(“水果销量分布图”, createRingChart2());
pieFrame.pack(); pieFrame.setVisible(true);

案例

package com.lizj_cdoc.jfreechartUtil;

import java.awt.Color;
import java.awt.Font;
import java.util.Locale;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.RingPlot;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;

public class CreateRingChart {
public static void main(String[] args) {
final ChartFrame frame = new ChartFrame(“Interval Bar Chart Demo”, createRingChart());
frame.pack();
frame.setVisible(true);
}
public static JFreeChart createRingChart() {
JFreeChart chart5 = ChartFactory.createRingChart(“环形分布图测试”,
getPieOrRingChartDataSet(), true, true, Locale.CHINESE);
setRingChart(chart5);
return chart5;
}
public static void setRingChart(JFreeChart chart) {
chart.setBackgroundPaint(Color.white);
RingPlot ringplot = (RingPlot) chart.getPlot();
ringplot.setLabelBackgroundPaint(Color.WHITE);
ringplot.setSectionPaint(0, new Color(128, 100, 162));
ringplot.setSectionPaint(1, new Color(155, 187, 89));
ringplot.setSectionPaint(2, new Color(192, 80, 77));
// ringplot.setLabelLinksVisible(false);
// 设置饼状图和环形图的显示数字。0代表显示文字说明,1代表显示数字,2代表显示数字以百分比的方式如果多个结合{0}:{1}
ringplot.setLabelGenerator(new StandardPieSectionLabelGenerator(“{2}”));
ringplot.setSimpleLabels(true);
ringplot.setLabelBackgroundPaint(new Color(1.0F, 0.75F, 0.0F, 0.0F));
ringplot.setLabelFont(new Font(“sans-serif”, Font.PLAIN, 12));
ringplot.setLabelOutlinePaint(new Color(1.0F, 0.75F, 0.0F, 0.0F));
ringplot.setLabelPaint(Color.white);
ringplot.setLabelFont(new Font(“微软雅黑”, Font.PLAIN, 24));
ringplot.setLabelShadowPaint(new Color(1.0F, 0.75F, 0.0F, 0.0F));
TextTitle title = chart.getTitle();
title.setFont(new Font(“sans-serif”, Font.PLAIN, 24));
// 设置深度,即带颜色圆环的宽度
ringplot.setSectionDepth(0.5d);
// 设置环形图背景颜色
ringplot.setBackgroundPaint(Color.white);

    chart.getLegend().setItemFont(new Font("微软雅黑", Font.BOLD, 12));
}
private static PieDataset getPieOrRingChartDataSet() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    /* dataset.setValue("1.0分-2.0分", new Double(0)); */
    dataset.setValue("2.0分-3.0分", new Double(10));
    dataset.setValue("3.0分-4.0分", new Double(10));
    dataset.setValue("4.0分-5.0分", new Double(80));

    return dataset;
}

}

这里写代码片
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值