echarts 中的 notMerge 参数

1,382 阅读1分钟

echarts 当使用 setOption API 的时候 notMerge 默认为 false 很有可能导致数据重复,

给人一种错误的感觉, 为什么我的 setOption 没有把数据替换 setOption API 支持的参数 合并规则

vue-echarts 组件也在前三天把 notMerge 默认设置改为了 true 提交记录

(option: Object, notMerge?: boolean, lazyUpdate?: boolean)
// option 是配置
// notMerge 代表是否将你的参数和之前的合并 合并规则还要你自己去看

猜想一下如果第一次数据是

{
 tooltip: {
   trigger: 'axis',
   axisPointer: {
     type: 'shadow'
   }
 },
 legend: {},
 grid: {
   left: '3%',
   right: '4%',
   bottom: '3%',
   containLabel: true
 },
 xAxis: [
   {
     type: 'category',
     data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
   }
 ],
 yAxis: [
   {
     type: 'value'
   }
 ],
 series: [
   {
     name: 'Direct',
     type: 'bar',
     emphasis: {
       focus: 'series'
     },
     data: [320, 332, 301, 334, 390, 330, 320]
   },
   {
     name: 'Email',
     type: 'bar',
     stack: 'Ad',
     emphasis: {
       focus: 'series'
     },
     data: [120, 132, 101, 134, 90, 230, 210]
   }
 ]
};

第二次的配置为

 {
 tooltip: {
   trigger: 'axis',
   axisPointer: {
     type: 'shadow'
   }
 },
 legend: {},
 grid: {
   left: '3%',
   right: '4%',
   bottom: '3%',
   containLabel: true
 },
 xAxis: [
   {
     type: 'category',
     data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
   }
 ],
 yAxis: [
   {
     type: 'value'
   }
 ],
 series: []
};

如果 notMerge 是默认的 false 那么合并之后的数据就很有可能是 series 没有置空, 像堆叠柱状图这种图标最好设置为 true