Highcharts与ECharts在大数据量下的使用与比较

业务需求

对百万级数据点进行绘制

Highcharts实现

使用Highcharts的Boost 模块实现该功能。Boost 模块由 WebGL 而不是默认的 SVG来实现图表的渲染,从而在几毫秒内呈现数十万个数据点。除了 WebGL 渲染之外,它还通过尽可能跳过数据的处理和检查来节省时间,但这可能导致在启用 Boost 模块后一些其他功能存在一些限制。

引入依赖项

javascript 复制代码
import Highcharts from "highcharts";
import boost from "highcharts/modules/boost";
boost(Highcharts)

关键配置项

javascript 复制代码
Highcharts.chart('container', {
    boost: {
      useGPUTranslations: true
    },
});

完整代码

javascript 复制代码
<template>
  <div id="app">
    <div id="container"></div>
  </div>
</template>

<script>
import Highcharts from "highcharts";
import boost from "highcharts/modules/boost";
boost(Highcharts)

export default {
  name: 'App',
  mounted () {
     this.getChart();
  },
  methods: {
    getChart(){
      var n = 1000000,
      data = this.getData(n);// 获取数据
      console.time('line');
      Highcharts.chart('container', {
        boost: {
          useGPUTranslations: true
        },
        title: {
          text: 'Highcharts drawing ' + n + ' points'
        },
        subtitle: {
          text: 'Using the Boost module'
        },
        tooltip: {
          valueDecimals: 2
        },
        series: [{
          data: data,
          lineWidth: 0.5
        }]
      });
      console.timeEnd('line');
    },
    getData(n) {
      var arr = [], i, a, b, c, spike;
      for (i = 0; i < n; i = i + 1) {
        if (i % 100 === 0) {
          a = 2 * Math.random();
        }
        if (i % 1000 === 0) {
          b = 2 * Math.random();
        }
        if (i % 10000 === 0) {
          c = 2 * Math.random();
        }
        if (i % 50000 === 0) {
          spike = 10;
        } else {
          spike = 0;
        }
        arr.push([i, 2 * Math.sin(i / 100) + a + b + c + spike + Math.random()]);
      }
      return arr;
    },
  }
}
</script>
<style>
.container{
  width: 400px;
  height: 400px;
}
</style>

效果图

数据渲染耗时:

ECharts实现

使用large属性启用大规模路径图的优化。是否开启大数据量优化,在数据图形特别多而出现卡顿时候可以开启。开启后配合 largeThreshold 在数据量大于指定阈值的时候对绘制进行优化。

缺点:优化后不能自定义设置单个数据项的样式。

引入依赖项

javascript 复制代码
import * as echarts from 'echarts';

关键配置项

javascript 复制代码
config =  {
    series: [
          {
            type: 'line',
            data: this.ydata,
            large: true
          }
      ]
};

完整代码

javascript 复制代码
<template>
  <div id="app">
    <div id="container"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  name: 'App',
  data () {
    return {
      xdata:[],
      ydata:[],
    }
  },
  mounted () {
     this.getEChart();
  },
  methods: {
    getECharts(){
      var n = 1000000,
      this.getData(n);// 获取数据
      console.time('echartsline');
      let EChart = echarts.init(document.getElementById("EChart"));
      let config = {
        title: { text: 'Echarts drawing ' + n + ' points' },
        tooltip: {
            trigger: 'axis'
        },
        xAxis: {
            silent: false,
            data:this.xdata
        },
        yAxis: {},
        series: [
          {
            type: 'line',
            data: this.ydata,
            large: true
          }
        ],
        
      };
      EChart.setOption(config);
      console.timeEnd('echartsline');
    },
    getData(n) {
      var arr = [], i, a, b, c, spike;
      for (i = 0; i < n; i = i + 1) {
        if (i % 100 === 0) {
          a = 2 * Math.random();
        }
        if (i % 1000 === 0) {
          b = 2 * Math.random();
        }
        if (i % 10000 === 0) {
          c = 2 * Math.random();
        }
        if (i % 50000 === 0) {
          spike = 10;
        } else {
          spike = 0;
        }
        arr.push([i, 2 * Math.sin(i / 100) + a + b + c + spike + Math.random()]);
        this.xdata.push(i);
        this.ydata.push(arr[i][1]);
      }
      return arr;
    },
  }
}
</script>
<style>
.container{
  width: 400px;
  height: 400px;
}
</style>

效果图

渲染时间对比

1w 20w 50w 100w 200w
Highcharts(折线图-1条) 106.7 ms 304.1 ms 1004.7 ms 1459.8 ms 2359.1 ms(tooltip几乎无延迟)
ECharts(折线图-1条) 66.1 ms 449.7 ms (tooltip卡顿) 1200.7 ms(tooltip卡顿) 2030.0 ms(tooltip卡顿) 4529.7 ms(tooltip卡顿)
Highcharts(折线图-5条) 151.5 ms 1082.6 ms 3205.9 ms 4734.0 ms -
ECharts(折线图-5条) 109.4 ms 1780.4 ms 4800.5 ms 10812.4 ms (25s) -
Highcharts(柱状图) 142.1 ms 480.5 ms 1012.4 ms 1521.5 ms 5869.1 ms
ECharts(柱状图) 54.2 ms 194.3 ms 339.9 ms 681.0 ms 449.7 ms

折线图:单条折线图时Highcharts与ECharts渲染时间在10w数据时基本持平,但ECharts在此数据量下tooltip仍然会出现卡顿的情况。10条折线时,15w数据量下,两者渲染时间基本持平,但ECharts在1.8w数据量时tooltip出现明显卡顿

柱状图:ECharts渲染时间远优于Highcharts

此demo使用版本:

json 复制代码
{
    "node": "^12.20.0",
    "highcharts": "^11.2.0",
    "echarts": "^5.0.0",
}
相关推荐
某公司摸鱼前端2 天前
uniapp 上了原生的 echarts 图表插件了 兼容性还行
前端·uni-app·echarts
柚乐果果3 天前
ECharts图表图例4
java·大数据·eclipse·echarts
幼儿园老大*3 天前
【Echarts】折线图和柱状图如何从后端动态获取数据?
前端·javascript·vue.js·经验分享·后端·echarts·数据可视化
盼兮*3 天前
栏目一:使用echarts绘制简单图形
前端·信息可视化·echarts
某公司摸鱼前端5 天前
uniapp微信小程序使用ucharts遮挡自定义tabbar的最佳解决方案
微信小程序·小程序·uni-app·echarts·ucharts
Jiaberrr5 天前
解锁微信小程序新技能:ECharts动态折线图搭配WebSocket,数据刷新快人一步!
前端·javascript·websocket·微信小程序·echarts
叫我:松哥6 天前
城市轨道交通网络客流大数据可视化分析系统----以某市交通网络客流数据为例
网络·数据库·python·信息可视化·前端框架·flask·echarts
晴天蜗牛不一般7 天前
隆重的给大家介绍一下 <BaseEcharts/>
前端·npm·echarts
toooooop88 天前
vue echarts tooltip使用动态模板
前端·vue.js·echarts
会跳舞的小猴子8 天前
echarts 导出pdf空白原因
javascript·pdf·echarts