html 环形图圆角,环形图圆角(原创)

9c9daae0389c060b9e37957e989250e1.png

c714816320c3c7678952c0af200e40b9.png

插件描述:本插件可以帮你创建以圆角为交界的环形图

本插件使用canvas可以帮助你快速创建一个以圆角交界的环形图

兼容性

适用于所有主流浏览器及移动端的浏览器。IE8及以下不支持

安装npm install donut-chart

用法

首先需要一个canvas做载体

然后创建环形图对象var cir = new DonutChart('myCanvas', option)

最后初始化并且可以指定回调函数cir.init(function (result) {

// result 选中的选区的相关信息

})

参数

option 示例 (默认值)var option = {

type: 'pie', // pie 环形图|| gauge 计量图

title: {

show: true,

text: '总资产(元)',

textStyle: {

fontSize: "20px",

lineHeight: "30px",

color: '#9f9f9f'

},

subtext: '360',

subtextStyle: {

fontSize: "30px",

lineHeight: "35px",

color: '#e53344'

},

x: '50%', // title 位置

y: "50%",

},

tooltip: {

show: true,

fontStyle: "normal",    // 规定字体样式 normal || italic || oblique

fontVariant: "normal",  // 规定字体变体 normal || small-caps

fontWeight: 'normal',   // 规定字体的粗细 normal || bold || bolder || lighter || 100 || 200 || 300 || 400 || 500 || 600 || 700 || 800 || 900

fontSize: "20px",   // 规定字号,以像素计

lineHeight: "30px", // 规定行高,以像素计

fontFamily: 'Arial',// 规定字体系列

color: 'white',     // 字体颜色

backgroundColor: '#00000099', // tip 背景

formatter: function (param) {   // 类似echarts 富文本编辑

var str = "{a|" + param.name + "}" + "{c|" + param.percent + "}" + '\n' + "{b|" + param.value +

"元}"

return str

},

rich: {

a: {

fontStyle: "normal",

fontVariant: "normal",

fontWeight: 'bold',

fontSize: "20px",

lineHeight: "30px",

fontFamily: 'Arial',

color: 'white',

},

c: {

fontStyle: "normal",

fontVariant: "normal",

fontWeight: 'normal',

fontSize: "20px",

lineHeight: "30px",

fontFamily: 'Arial',

color: 'white',

},

b: {

fontStyle: "normal",

fontVariant: "normal",

fontWeight: 'bold',

fontSize: "30px",

lineHeight: "35px",

fontFamily: 'Arial',

color: '#e53344',

}

}

},

x: "50%",   // 图标位置

y: "50%",

radius: "30%",  // 半径

lineWidth: "5%", // 圆环宽度

// {{if type === gauge 计量图}}

// max: 120, // 映射总值

// data: [{

//     name: "已用时长(分钟)",

//     value: 85, // 映射计量值

// }],

// {{else if type === pie 环形图}}

// data: [{

//     name: "账户余额(元)",

//     value: 110,

// }, {

//     name: "散标待回(元)",

//     value: 120,

// }, {

//     name: "在途资金(元)",

//     value: 130,

// }],

// {{/if}}

label: {

show: true,

fontStyle: "normal",

fontVariant: "normal",

fontWeight: 'bold',

fontSize: "20px",

lineHeight: "30px",

fontFamily: 'Arial',

color: '#9f9f9f',

formatter: function (param) {

var str = "{a|" + param.name + "}" + "{c|" + param.percent + "}" + '\n' + "{b|" + param.value +

"元}"

return str

},

rich: {

a: {

fontStyle: "normal",

fontVariant: "normal",

fontWeight: 'bold',

fontSize: "20px",

lineHeight: "30px",

fontFamily: 'Arial',

},

b: {

fontStyle: "normal",

fontVariant: "normal",

fontWeight: 'bold',

fontSize: "30px",

lineHeight: "35px",

fontFamily: 'Arial',

color: '#e53344',

},

c: {

fontStyle: "normal",

fontVariant: "normal",

fontWeight: 'bold',

fontSize: "20px",

lineHeight: "30px",

fontFamily: 'Arial',

}

}

},

capType: "round", // 圆角 || butt 平角

selectedStyle: {  // 选中时的样式

color: "white", // 包边颜色

borderWidth: 10 // 包边宽度

},

color: ["#fe7c00", "#e83227", "#32a676"],

labelCoverTitle: true, // label 是否覆盖标题

backgroundArc: '#999' // 空圆环的颜色

}

ECharts 圆角环形是一种数据可视化表,可以通过饼的形式展示数据占比情况。与普通饼不同的是,圆角环形具有内外两个圆环,可以更好地展示数据占比情况。圆角环形的优点在于它可以更好地展示不同数据之间的比例关系,同时也可以显示每个数据项的具体数值。 使用ECharts绘制圆角环形需要以下几个步骤: 1. 导入ECharts库和主题 ``` <script src="https://cdn.bootcdn.net/ajax/libs/echarts/4.9.0/echarts.min.js"></script> ``` 2. 创建一个容器 ``` <div id="chart" style="width: 600px;height:400px;"></div> ``` 3. 初始化ECharts实例 ``` var myChart = echarts.init(document.getElementById('chart')); ``` 4. 配置表 ``` option = { title: { text: '圆角环形' }, tooltip: { trigger: 'item', formatter: "{a} <br/>{b}: {c} ({d}%)" }, legend: { orient: 'vertical', x: 'left', data:['数据1','数据2','数据3','数据4','数据5'] }, series: [ { name:'访问来源', type:'pie', radius: ['50%', '70%'], avoidLabelOverlap: false, label: { show: false, position: 'center' }, emphasis: { label: { show: true, fontSize: '20', fontWeight: 'bold' } }, labelLine: { show: false }, data:[ {value:335, name:'数据1'}, {value:310, name:'数据2'}, {value:234, name:'数据3'}, {value:135, name:'数据4'}, {value:1548, name:'数据5'} ] } ] }; ``` 5. 渲染表 ``` myChart.setOption(option); ``` 以上就是使用ECharts绘制圆角环形的步骤。根据实际需求,可以根据需要调整表的样式和配置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值