Toggle navigation
折现区域说明
By
请***生
2018-09-05 00:19:21
脚本
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
图表已生成
整理代码
刷新
代码
function profileDataGenerater() { var data = [[], [], [], []]; while (data[0].length !== pointNumber) { data[0].push('柱号00+' + (data[0].length + 1)); data[1].push(random(15, 20)); data[2].push(random(25, 30)); data[3].push(random(35, 40)); } return data; } /** * 产生随机整数,包含下限值,但不包括上限值 * @param {Number} lower 下限 * @param {Number} upper 上限 * @return {Number} 返回在下限到上限之间的一个随机整数 */ function random(lower, upper) { return Math.floor(Math.random() * (upper - lower)) + lower; } /** * 在设定的长度中随机取两个值 * @return {Number[]} 返回在设定范围内的一个区间 */ function randomSection() { var secLower = 0; var secUpper = 0; while (secUpper - secLower < 15) { secLower = Math.floor(Math.random() * pointNumber); secUpper = Math.floor(Math.random() * pointNumber); [secLower, secUpper] = secUpper < secLower ? [secUpper, secLower] : [secLower, secUpper] } return [secLower, secUpper]; } function getSectionInfo(arrs) { var sectionData = []; var pointData = []; var data = arrs.slice(1); var cursor = arrs[0]; var yMax = Math.floor(Math.max(...data[0], ...data[1], ...data[2])); var yLength = Math.floor(yMax * 0.25); var baseDif = 2; data.forEach((arr, idx) => { var [secLower, secUpper] = randomSection(); var height = yMax + yLength * (idx + 1); pointData.push({ name: cursor[secLower], value: [cursor[secLower], arr[secLower]], }, { name: cursor[secUpper], value: [cursor[secUpper], arr[secUpper]], }); sectionData.push( [ { symbol: 'arrow', name: `两个坐标之间的说明${idx + 1}`, coord: [cursor[secLower], height] }, { symbol: 'arrow', coord: [cursor[secUpper], height] } ], [ { symbol: 'none', coord: [cursor[secLower], height + baseDif] }, { symbol: 'none', coord: [cursor[secLower], height - baseDif] } ], [ { symbol: 'none', coord: [cursor[secUpper], height + baseDif] }, { symbol: 'none', coord: [cursor[secUpper], height - baseDif] } ] ); }); return [sectionData, pointData]; } function profileOptionHandler({ data, sectionData, pointData }) { var COMMONSTYLE = { type: 'line', silent: true, animation: false, symbolSize: 0, hoverAnimation: false, lineStyle: { normal: { width: 1 } } }; var yMax = Math.floor(Math.max(...data[1], ...data[2], ...data[3]) * 1.25); var option = { title: { text: `黄河${data[0][0]}~${data[0][data.length - 1]}剖面图`, left: 'center', bottom: 20 }, grid: { bottom: 150 }, xAxis: [{ axisLine: { show: false }, axisTick: { show: false }, axisLabel: { rotate: 90 }, data: data[0] }], yAxis: [{ max: Math.floor(yMax * 1.5), axisLabel: { formatter: (value) => value.toFixed(2) } }], series: [ Object.assign( { markLine: { silent: true, animation: false, label: { normal: { position: 'middle' } }, lineStyle: { normal: { color: "#626c91", type: 'solid', width: 1 }, emphasis: { color: "#d9def7" } }, data: sectionData } }, COMMONSTYLE ), Object.assign( {}, COMMONSTYLE, { type: 'scatter', data: pointData, symbolSize: 10, label: { normal: { show: true, position: 'bottom', formatter: function (params) { console.log(params) return params.data.name; } } }, itemStyle: { normal: { color: 'red', opacity: 1 } } } ), Object.assign( { data: data[1] }, COMMONSTYLE ), Object.assign( { data: data[2] }, COMMONSTYLE ), Object.assign( { data: data[3] }, COMMONSTYLE ) ] } return option; } var pointNumber = 50; var profileData = profileDataGenerater(); var [sectionData, pointData] = getSectionInfo(profileData); var option = profileOptionHandler({ data: profileData, sectionData: sectionData, pointData: pointData });