1 环境: vue-cli(2.0)+ vue-echarts (git地址:https://github.com/ecomfe/vue-echarts)
2 场景:最近项目用echarts来展示图标,其中有一个需求,需要拖动手柄,等松开手柄时,要根据手柄所在的位置(获取手柄在的x轴信息),重新发送请求,来渲染数据。
echarts的手柄实例地址:http://echarts.baidu.com/examples/editor.html?c=line-tooltip-touch
3图:
4遇到的bug:
4.1 手柄上的label信息,有时会刷新不出来。即上图中的2016-10-07消失。
4.2 echarts的点击事件对折线图并不友好,必须点在折线图的点坐标上才会触发事件。so,要实现点击图中任意位置来即可实现触发自己的事件。
4.3 echarts提供了可以拖动的手柄,但是并没有松开手柄后触发的事,这个没有满足我们产品的需求。当然有可能是我没有找到,若有请告知,谢谢。
5解决以上的bug:
页面的展示如下:
<template> <div> <div id='line' @touchend='touchs' @mouseup='touchs'> <v-chart auto-resize class='zhexian' :options='lineOption' :initOptions='initOptions' ref='line' /> </div> </div></template><script> //初始化折线的数据 import lineoption from '@/assets/js/handleline.js' export default{ data(){ return{ lineOption:lineoption, initOptions:{ renderer: 'svg' || 'canvas' }, date:'',//发送Ajax时所需的参数 reFlag:'',//避免重复发送请求时的中间变量 } }, } </script>拖动手柄时,会实时触发formater,
解决第一个bug ,label有时会消失,因为我以后的代码会用到formatter,第一次要用formater ,我是这样写的,
this.lineOption.xAxis.axisPoint.label.formatter=function(param){
//param是X轴的信息
2 let value = _this.$echart.format.formatTime('yyyy-MM-dd', params.value);
3 _this.date =value;
4 console.log('实时获取的X轴的事件'+_this.date)
5 return value;
6},,axisPoint对象的其他数据写在了handleline.js中,解决方案就是把axisPoint的其他数据也重新setOption了,
mounted(){
2 //
3 let _this = this;
4 this.lineOption.xAxis.axisPointer={
5 value: '2016-10-7',
6 snap: true,
7 lineStyle: {

