【问题标题】:Any solution to reduce loading time when using localStorage?使用 localStorage 时有什么解决方案可以减少加载时间?
【发布时间】:2021-04-22 03:23:07
【问题描述】:

我找到一个sample 来使用localStorage 保存选定的LegendItems。

但是当数据太大时,图表的加载速度变慢了,

这是我的demo

events: {
  load: function() { ... }

有没有办法解决这个问题?

【问题讨论】:

  • 看起来很慢的部分是series[i].update()。每次迭代大约需要 350 毫秒,其中有 90 次,这只是 CPU 时间。我相信它与 LocalStorage 无关。

标签: javascript jquery highcharts local-storage


【解决方案1】:

您可以使用与单击事件处理程序相同的方法 - 在循环后重绘图表,而不是在每次迭代中。

events: {
  load: function() {
    ...
    if (!localStorage.legendItems) {
      ...
    } else {
      ...
      legendBooleans.forEach(function(state, i) {
        series[i].update({
          visible: state
        }, false);
      })
                
      this.redraw();
    }
  } 
}

现场演示: https://jsfiddle.net/BlackLabel/zufLce9h/

API 参考: https://api.highcharts.com/class-reference/Highcharts.Series#update

【讨论】:

  • 我明白了,我只会在for循环后使用redraw,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-22
  • 1970-01-01
  • 2018-07-19
  • 2023-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多