Echarts --柱状图动态提示框 tooltip
效果如图所示,阴影部分及提示框隔五秒移动一次
下面贴上echarts官网 实例中测试的源码
1 var timmerOneAnim=null; 2 var namedata = [ 3 "姑苏区", 4 "虎丘区", 5 "吴中区", 6 "相城区", 7 "吴江区", 8 "工业园区", 9 "常熟区", 10 "昆山市", 11 "张家港市", 12 "太仓市" 13 ]; // var areaChart = this.$echarts.init(document.getElementById("xxx")); 14 var option = { 15 tooltip: { 16 //提示框组件 17 trigger: "axis", 18 formatter: "{b}<br/>{a0}: {c0}<br/>{a1}: {c1}<br/>{a2}: {c2}", 19 axisPointer: { 20 type: "shadow", 21 label: { 22 backgroundColor: "#6a7985" 23 } 24 }, 25 textStyle: { 26 color: "#fff", 27 fontStyle: "normal", 28 fontFamily: "微软雅黑", 29 fontSize: 12 30 } 31 }, 32 grid: { 33 top: "15%", 34 bottom: "10%", 35 right: "5%", 36 left: "5%", 37 containLabel: true 38 }, 39 legend: { 40 //图例组件,颜色和名字 41 right: "35%", 42 top: "2%", 43 itemGap: 16, 44 itemWidth: 18, 45 itemHeight: 10, 46 data: [ 47 { 48 name: "村" 49 }, 50 { 51 name: "区" 52 }, 53 { 54 name: "街路巷" 55 } 56 ], 57 textStyle: { 58 color: "#a8aab0", 59 fontStyle: "normal", 60 fontFamily: "微软雅黑", 61 fontSize: 12 62 } 63 }, 64 xAxis: [ 65 { 66 type: "category", 67 data: namedata, 68 axisLabel: { 69 //坐标轴刻度标签的相关设置。 70 interval: 0, //设置为 1,表示『隔一个标签显示一个标签』 71 textStyle: { 72 color: "#6C7293", 73 fontStyle: "normal", 74 fontFamily: "微软雅黑", 75 fontSize: 12 76 }, 77 rotate: 0 78 }, 79 axisTick: { 80 //坐标轴刻度相关设置。 81 show: false 82 }, 83 axisLine: { 84 //坐标轴轴线相关设置 85 lineStyle: { 86 color: "#fff", 87 opacity: 0.2 88 } 89 }, 90 splitLine: { 91 //坐标轴在 grid 区域中的分隔线。 92 show: false 93 } 94 } 95 ], 96 yAxis: [ 97 { 98 type: "value", 99 splitNumber: 5, 100 axisLabel: { 101 textStyle: { 102 color: "#a8aab0", 103 fontStyle: "normal", 104 fontFamily: "微软雅黑", 105 fontSize: 12 106 } 107 }, 108 axisLine: { 109 show: false 110 }, 111 axisTick: { 112 show: false 113 }, 114 splitLine: { 115 show: true, 116 lineStyle: { 117 color: "#EAEBF0" 118 } 119 } 120 } 121 ], 122 series: [ 123 { 124 name: "村", 125 type: "bar", 126 data: [ 127 10, 128 45, 129 30, 130 45, 131 15, 132 5, 133 62, 134 8, 135 60, 136 32, 137 60, 138 55, 139 45, 140 30, 141 15, 142 10 143 ], 144 barWidth: 6, 145 barGap: 0.5, //柱间距离 146 itemStyle: { 147 normal: { 148 show: true, 149 color: "#7A79FF", 150 barBorderRadius: 50, 151 borderWidth: 0 152 } 153 } 154 }, 155 { 156 name: "区", 157 type: "bar", 158 data: [ 159 10, 160 15, 161 30, 162 45, 163 55, 164 60, 165 62, 166 30, 167 80, 168 62, 169 60, 170 55, 171 45, 172 30, 173 15, 174 7 175 ], 176 barWidth: 6, 177 barGap: 0.5, //柱间距离 178 itemStyle: { 179 normal: { 180 show: true, 181 color: "#58CFFF", 182 barBorderRadius: 50, 183 borderWidth: 0 184 } 185 } 186 }, 187 { 188 name: "街路巷", 189 type: "bar", 190 data: [10, 15, 30, 45, 5, 60, 62, 10, 80, 2, 40, 55, 45, 30, 45, 8], 191 barWidth: 6, 192 barGap: 0.5, //柱间距离 193 itemStyle: { 194 normal: { 195 show: true, 196 color: "#333FFF", 197 barBorderRadius: 50, 198 borderWidth: 0 199 } 200 } 201 } 202 ] 203 }; 204 205 // tooltip定时移动 注意:vue项目中 myChart换成自己初始化的名称(我的是areaChart) 206 var count = 0; 207 if (timmerOneAnim) { 208 clearInterval(timmerOneAnim); 209 } 210 timmerOneAnim = setInterval(() => { 211 myChart.dispatchAction({ 212 type: "showTip", 213 seriesIndex: 0, 214 dataIndex: count % namedata.length 215 }); 216 count++; 217 }, 5000);
1 <template> 2 <div id="bzdzArea"></div> 3 </template> 4 <script> 5 export default { 6 name: "MultipleColumns", 7 data() { 8 return { 9 timmerOneAnim: null 10 }; 11 }, 12 methods: { 13 getbzdzAreaChart() { 14 var namedata = [ 15 "姑苏区", 16 "虎丘区", 17 "吴中区", 18 "相城区", 19 "吴江区", 20 "工业园区", 21 "常熟区", 22 "昆山市", 23 "张家港市", 24 "太仓市" 25 ]; 26 var areaChart = this.$echarts.init(document.getElementById("bzdzArea")); 27 var option = { 28 tooltip: { 29 //提示框组件 30 trigger: "axis", 31 formatter: "{b}<br/>{a0}: {c0}<br/>{a1}: {c1}<br/>{a2}: {c2}", //提示框浮层内容格式器 32 axisPointer: { //坐标轴指示器 33 type: "shadow", //'shadow' 阴影指示器 34 label: { 35 backgroundColor: "#6a7985" 36 } 37 }, 38 textStyle: { 39 color: "#fff", 40 fontStyle: "normal", 41 fontFamily: "微软雅黑", 42 fontSize: 12 43 } 44 }, 45 grid: { 46 top: "15%", 47 bottom: "10%", 48 right: "5%", 49 left: "5%", 50 containLabel: true 51 }, 52 legend: { //图例组件 53 right: "35%", 54 top: "2%", 55 itemGap: 16, 56 itemWidth: 18, 57 itemHeight: 10, 58 data: [ 59 { 60 name: "村" 61 }, 62 { 63 name: "区" 64 }, 65 { 66 name: "街路巷" 67 } 68 ], 69 textStyle: { 70 color: "#a8aab0", 71 fontStyle: "normal", 72 fontFamily: "微软雅黑", 73 fontSize: 12 74 } 75 }, 76 xAxis: [ 77 { 78 type: "category", 79 data: namedata, 80 axisLabel: { 81 //坐标轴刻度标签的相关设置。 82 interval: 0, //设置为 1,表示『隔一个标签显示一个标签』 83 textStyle: { 84 color: "#6C7293", 85 fontStyle: "normal", 86 fontFamily: "微软雅黑", 87 fontSize: 12 88 }, 89 rotate: 0 90 }, 91 axisTick: { 92 //坐标轴刻度相关设置。 93 show: false 94 }, 95 axisLine: { 96 //坐标轴轴线相关设置 97 lineStyle: { 98 color: "#fff", 99 opacity: 0.2 100 } 101 }, 102 splitLine: { 103 //坐标轴在 grid 区域中的分隔线。 104 show: false 105 } 106 } 107 ], 108 yAxis: [ 109 { 110 type: "value", 111 splitNumber: 5, 112 axisLabel: { 113 textStyle: { 114 color: "#a8aab0", 115 fontStyle: "normal", 116 fontFamily: "微软雅黑", 117 fontSize: 12 118 } 119 }, 120 axisLine: { 121 show: false 122 }, 123 axisTick: { 124 show: false 125 }, 126 splitLine: { 127 show: true, 128 lineStyle: { 129 color: "#EAEBF0" 130 } 131 } 132 } 133 ], 134 series: [ 135 { 136 name: "村", 137 type: "bar", 138 data: [ 10, 45, 30, 45, 15, 5, 62, 8, 60, 32, 60, 55, 45, 30, 15, 10 ], 139 barWidth: 6, 140 barGap: 0.5, //柱间距离 141 itemStyle: { 142 normal: { 143 show: true, 144 color: "#7A79FF", 145 barBorderRadius: 50, 146 borderWidth: 0 147 } 148 } 149 }, 150 { 151 name: "区", 152 type: "bar", 153 data: [ 10, 15, 30, 45, 55, 60, 62, 30, 80, 62, 60, 55, 45, 30, 15, 7 ], 154 barWidth: 6, 155 barGap: 0.5, //柱间距离 156 itemStyle: { 157 normal: { 158 show: true, 159 color: "#58CFFF", 160 barBorderRadius: 50, 161 borderWidth: 0 162 } 163 } 164 }, 165 { 166 name: "街路巷", 167 type: "bar", 168 data: [10, 15, 30, 45, 5, 60, 62, 10, 80, 2, 40, 55, 45, 30, 45, 8], 169 barWidth: 6, 170 barGap: 0.5, //柱间距离 171 itemStyle: { 172 normal: { 173 show: true, 174 color: "#333FFF", 175 barBorderRadius: 50, 176 borderWidth: 0 177 } 178 } 179 } 180 ] 181 }; 182 areaChart.setOption(option); 183 // tooltip定时移动 184 var count = 0; 185 if (this.timmerOneAnim) { 186 clearInterval(this.timmerOneAnim); 187 } 188 this.timmerOneAnim = setInterval(() => { 189 areaChart.dispatchAction({ 190 type: "showTip", 191 seriesIndex: 0, 192 dataIndex: count % namedata.length 193 }); 194 count++; 195 }, 5000); 196 } 197 }, 198 mounted() { 199 this.getbzdzAreaChart(); 200 } 201 }; 202 </script> 203 <style> 204 </style>