Toggle navigation
渠道分布-饼图
By
l***b
2020-05-22 01:46:30
脚本
16
21
作品使用的第三方脚本
数据管理
上传数据
支持小于 5M 任意格式(csv, xlsx, json, xml, ...)的数据文件
上传后可以通过生成的文件链接异步获取托管的数据。
历史数据
0 条
无历史数据
代码修改记录
信息提示
保存作品
对当前截图不满意?你还可以
上传本地截图
重新截图
作品名称
作品描述
标签
geo
grid
legend
markLine
markPoint
bar
effectScatter
line
lines
map
timeline
title
toolbox
tooltip
visualMap
作品默认版本
最新
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
20:11:45
图表已生成
整理代码
刷新
代码
/** * 获取字符串的字节长度 * @param str * @returns {number} */ function getByteLength(str) { let byteLen = 0 if (typeof str === 'string') { const len = str.length for (let i = 0; i < len; i++) { const code = str.charCodeAt(i) let byte // 单字节加1 if ((code >= 0x0001 && code <= 0x007e) || (code >= 0xff60 && code <= 0xff9f)) { byte = 1 } else { byte = 2 } byteLen += byte } } return byteLen } /** * 按字节长度截取字符串,返回截取的endIndex * @param str * @param cutByteLen * @returns {number} */ function cutString(str, cutByteLen = 20) { if (typeof str === 'string' && typeof cutByteLen === 'number') { const len = str.length let cutIndex = len let byteLen = 0 for (let i = 0; i < len; i++) { const code = str.charCodeAt(i) let byte if ((code >= 0x0001 && code <= 0x007e) || (code >= 0xff60 && code <= 0xff9f)) { byte = 1 } else { byte = 2 } if (byteLen + byte < cutByteLen) { byteLen += byte } else { cutIndex = i break } } return cutIndex } return -1 } /** * 分割字符串 * @param str * @param cutByteLen * @returns {[]} */ function splitStr(str, cutByteLen = 20) { let text = str const strs = [] for (let i = 0; getByteLength(text) > 0; i++) { const cutIndex = cutString(text, cutByteLen) strs.push(text.substr(0, cutIndex + 1)) text = text.substr(cutIndex + 1) } return strs } /** * 字符串超过一定长度添加省略号 * @param str * @param cutByteLen * @returns {string|*} */ function omitStr(str, cutByteLen = 20) { const cutIndex = cutString(str, cutByteLen) if (cutIndex < str.length - 1) { return `${str.substr(0, cutIndex + 1)}...` } return str } const data = [{ "name": "默认渠道", "value": 118 }, { "name": "网页渠道", "value": 16 }, { "name": "test hello world", "value": 6 }, { "name": "零一二三四五六七八九零一二三四五六七八九", "value": 2 }, { "name": "未知渠道", "value": 10 }, { "name": "1", "value": 1, }, { "name": "2", "value": 1, }, { "name": "3", "value": 1, }, { "name": "4", "value": 1, }, { "name": "5", "value": 1, }, { "name": "6", "value": 1, }, { "name": "7", "value": 1, }, { "name": "8", "value": 1, }, { "name": "9", "value": 1, }, { "name": "10", "value": 1, }, ]; option = { "backgroundColor": "#FFF", "color": [ "#1791FF", "#7870FF", "#41CBAB", "#FFC653", "#FF6519", "#EE3939", "#407AFB", "#4391FF", "#38A5FD", "#36B0FE", "#60AABD", "#6BB092", "#CBC718", "#F57C00", "#FF1A19" ], "tooltip": { "trigger": "item", "show": false }, "legend": { "type": "scroll", "icon": "circle", "itemGap": 24, "itemWidth": 8, "pageIconColor": "#595959", "orient": "vertical", "top": "4.6%", "left": "70%", "bottom": "4.6%", "data": [ "默认渠道", "网页渠道", "test hello world", "零一二三四五六七八九零一二三四五六七八九", "未知渠道", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", ], "formatter": function(name) { return omitStr(name) }, "textStyle": { "color": "#595959", "fontSize": 14 } }, "series": [{ "name": "人数", "type": "pie", "data": data, "itemStyle": { "borderColor": "#fff", "borderWidth": 1 }, "radius": [ "40%", "50.2%" ], "center": [ "50%", "50%" ], "splitNumber": -1, "label": { position: 'center', // 标签在饼图中心位置 formatter() { const name = data.length ? '渠道分布' : '' return `{name|${name}}` }, backgroundColor: '#fff', rich: { name: { fontSize: 12, color: '#222', }, }, }, "labelLine": { "show": false }, }] };