Toggle navigation
各类型线路收入占比分析
By
a***7
2020-08-20 03:34:00
脚本
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
图表已生成
整理代码
刷新
代码
const startAlpha = 1; const endAlpha = 0; const color = [{ r: 70, g: 240, b: 255 }, { r: 26, g: 255, b: 198 }, { r: 54, g: 90, b: 206 }, { r: 143, g: 114, b: 244 } ] const data = [{ name: "广州公交 6025.76 60%", value: 6025.76, _startArc: 0, _endArc: 3.0471975511965976, _color: "#46F0FF", _percent: 0.16666666666666666 }, { name: "佛山公交 2221.06 20%", value: 2221.06, _startArc: 3.0471975511965976, _endArc: 3.665191429188092, _color: "#1AFFC6", _percent: 0.4166666666666667 }, { name: "广州地区 2000.01 10%", value: 2000.01, _startArc: 3.665191429188092, _endArc: 7.9269908169872414, _color: "#365ACE", _percent: 0.041666666666666664 }, { name: "外围六区 1236.23 10%", value: 1236.23, _startArc: 3.9269908169872414, _endArc: 5.759586531581288, _color: "#8F72F4", _percent: 0.2916666666666667 }] /** * 线性渐变起止方向的计算方法 * * * @param {*} startArc 开始角度 * @param {*} endArc 结束角度 * @returns 四个坐标 x,y,x2,y2 */ function getCoordinates(startArc, endArc) { const posi = [ Math.sin(startArc), -Math.cos(startArc), Math.sin(endArc), -Math.cos(endArc) ] const dx = posi[2] - posi[0] const dy = posi[3] - posi[1] return getLocation(dx, dy) } function getLocation(dx, dy) { const tanV = dx / dy const directSign = Math.abs(tanV) < 1 const t = directSign ? tanV : 1 / tanV const sign1 = t > 0 ? 1 : -1 const sign2 = dx > 0 ? 1 : -1 const sign = directSign ? sign1 * sign2 : sign2 const group1 = [ 0.5 - sign * t / 2, 0.5 + sign * t / 2] const group2 = sign > 0 ? [0, 1] : [1, 0] const group = [...group1, ...group2] const keys = directSign ? ['x', 'x2', 'y', 'y2'] : ['y', 'y2', 'x', 'x2' ] let res = {} keys.forEach((k, idx) => { res[k] = group[idx] }) return res } /** * 给数据写入 样式(线性渐变) * * @param {*} datas 数据 * @param {*} colorlist 颜色列表 * @param {*} startAlpha 开始颜色的透明度 * @param {*} endAlpha 结束颜色透的明度 * @returns 带样式的数据 */ function setGradientColorInItemSyle(datas, colorlist, startAlpha, endAlpha) { for (let i = 0; i < datas.length; i++) { const color = colorlist[i]; const startArc = datas[i]._startArc; const endArc = datas[i]._endArc; // 这里计算了 线性渐变的起止方向 const coordinates = getCoordinates(startArc, endArc); datas[i].itemStyle = { color: { ...coordinates, type: "linear", global: false, // 这里给了 线性渐变的起止颜色 colorStops: [{ offset: 0, color: `rgba(${color.r}, ${color.g}, ${color.b}, ${startAlpha})` }, { offset: 1, color: `rgba(${color.r}, ${color.g}, ${color.b}, ${endAlpha})` }] } } } return datas } option = { backgroundColor: '#101736', title: { text: "各类型线路收入占比分析", x: "4%", width: 173, height: 163, fontSize: 22, textStyle: { color: '#fff', fontSize: '22' }, subtextStyle: { color: '#90979c', fontSize: '16', }, }, color: ['#46F0FF', '#1AFFC6', '#365ACE', '#8F72F4'], tooltip: { trigger: "item", formatter: "{b}" }, legend: { orient:'vertical', icon: 'circle', //图例形状 bottom:'25%', right:'10%', itemWidth: 14, // 图例标记的图形宽度。[ default: 25 ] itemHeight: 14, // 图例标记的图形高度。[ default: 14 ] itemGap: 21, // 图例每项之间的间隔。[ default: 10 ]横向布局时为水平间隔,纵向布局时为纵向间隔。 textStyle: { fontSize: 14, color: '#fff', } }, series: [{ type: "pie", data: setGradientColorInItemSyle(data, color, startAlpha, endAlpha), // "animation": false, radius: [50, 60], center: ["30%", "50%"], labelLine: { show: false }, label:{ show: false } }] };