echart 状态区间图
这种图形在案例中有类似的http://echarts.baidu.com/demo.html#custom-profile,是根据这个来的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | function getviewbystation() { var myChart = echarts.init(document.getElementById( 'chartContent' )); //加载图形的div var colors = [ '#2EC7C9' , '#D6737A' ]; //两种状态的颜色 var state = [ '正常' , '故障' ]; //两种状态 // echart配置 var option = { color: colors, tooltip: { //提示框 formatter: function (params) { return params.name + ':' + params.value[1] + '~' + params.value[2]; } //数据的值 }, legend: { //图例 data: state, bottom: '1%' , selectedMode: false , // 图例设为不可点击 textStyle: { color: '#000' } }, grid: { //绘图网格 left: '3%' , right: '3%' , top: '1%' , bottom: '10%' , containLabel: true }, xAxis: { type: 'time' , interval: 3600 * 12 * 1000, axisLabel: { formatter: function (value) { var date = new Date(value); return getzf(date.getHours()) + ':' + getzf(date.getMinutes()) + '\n' + date.getDate() + '/' + (date.getMonth() + 1) + ' ' ; function getzf(num) { if (parseInt(num) < 10) { num = '0' + num; } return num; } }, } }, yAxis: { data: [ '监测站一' , '监测站二' , '监测站三' ] }, series: [ // 用空bar来显示四个图例 { name: state[0], type: 'bar' , data: [] }, { name: state[1], type: 'bar' , data: [] }, { type: 'custom' , renderItem: function (params, api) { //开发者自定义的图形元素渲染逻辑,是通过书写 renderItem 函数实现的 var categoryIndex = api.value(0); //这里使用 api.value(0) 取出当前 dataItem 中第一个维度的数值。 var start = api.coord([api.value(1), categoryIndex]); // 这里使用 api.coord(...) 将数值在当前坐标系中转换成为屏幕上的点的像素值。 var end = api.coord([api.value(2), categoryIndex]); var height = 24; //柱体宽度 return { type: 'rect' , // 表示这个图形元素是矩形。还可以是 'circle', 'sector', 'polygon' 等等。 shape: echarts.graphic.clipRectByRect({ // 矩形的位置和大小。 x: start[0], y: start[1] - height / 2, width: end[0] - start[0], height: height }, { // 当前坐标系的包围盒。 x: params.coordSys.x, y: params.coordSys.y, width: params.coordSys.width, height: params.coordSys.height }), style: api.style() }; }, encode: { x: [1, 2], // data 中『维度1』和『维度2』对应到 X 轴 y: 0 // data 中『维度0』对应到 Y 轴 }, data: [ // 维度0 维度1 维度2 { itemStyle: { normal: { color: colors[0] } }, //条形颜色 name: '正常' , value: [0, '2009/6/1 2:00' , '2009/6/1 24:00' ] //0,1,2代表y轴的索引,后两位代表x轴数据开始和结束 }, { itemStyle: { normal: { color: colors[1] } }, name: '故障' , value: [0, '2009/6/2 2:00' , '2009/6/2 12:00' ] }, { itemStyle: { normal: { color: colors[0] } }, name: '正常' , value: [0, '2009/6/2 13:10' , '2009/6/2 20:13' ] }, { itemStyle: { normal: { color: colors[1] } }, name: '故障' , value: [0, '2009/6/2 21:00' , '2009/6/4 1:00' ] }, { itemStyle: { normal: { color: colors[0] } }, name: '正常' , value: [0, '2009/6/4 2:00' , '2009/6/5 4:00' ] }, { itemStyle: { normal: { color: colors[0] } }, name: '正常' , value: [0, '2009/6/13 2:00' , '2009/6/21 12:00' ] }, { itemStyle: { normal: { color: colors[0] } }, name: '正常' , value: [1, '2009/6/1 2:00' , '2009/6/13 22:00' ] }, { itemStyle: { normal: { color: colors[1] } }, name: '故障' , value: [1, '2009/6/13 22:00' , '2009/6/22 23:00' ] }, { itemStyle: { normal: { color: colors[1] } }, name: '故障' , value: [1, '2009/6/30 22:00' , '2009/6/30 23:30' ] }, { itemStyle: { normal: { color: colors[1] } }, name: '故障' , value: [2, '2009/6/10 22:00' , '2009/6/30 23:30' ] }, ] } ] }; myChart.setOption(option); //引用 } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!