简体   繁体   English

提高Highcharts折线图的性能

[英]Improve performance of Highcharts line chart

I'm using Highcharts to create a zoomable line chart that has 1440 data points, here's a JSFiddle demo thereof. 我正在使用Highcharts创建一个包含1440个数据点的可缩放折线图,这是一个JSFiddle演示

In Firefox, the performance of the chart is very sluggish, it takes several seconds to render, and there's a long delay between hovering over a datapoint and the tooltip appearing. 在Firefox中,图表的性能非常缓慢,渲染需要几秒钟,并且在数据点上方悬停和出现工具提示之间存在很长的延迟。 On my page there are several such charts and their combined impact makes the page almost unusable. 在我的页面上有几个这样的图表,它们的综合影响使页面几乎无法使用。

Are there any tricks/tips for improving the performance of charts that have relatively large data sets? 是否有任何技巧/提示可以改善具有相对较大数据集的图表的性能? I've appended the chart's JSON to the end of this post (with the data itself truncated). 我已将图表的JSON附加到此帖的末尾(数据本身被截断)。

Incidentally, before I added the turboThreshold: 0 property the chart didn't render at all because the series has more than 1000 data points. 顺便说一下,在我添加turboThreshold: 0属性之前,图表根本没有渲染,因为该系列有超过1000个数据点。 According to the docs : 根据文件

When a series contains a data array that is longer than this, only one dimensional arrays of numbers, or two dimensional arrays with x and y values are allowed. 当一个系列包含一个比这长的数据数组时,只允许一维数字数组或具有x和y值的二维数组。 Also, only the first point is tested, and the rest are assumed to be the same format. 此外,仅测试第一个点,并假设其余的格式相同。 This saves expensive data checking and indexing in long series. 这样可以长时间地节省昂贵的数据检查和索引。 Set it to 0 disable. 将其设置为0禁用。 Defaults to 1000. 默认为1000。

$(function () {
    $('#container').highcharts({

        chart: {
            type: 'line',
            marginRight: 10,
            zoomType: 'x'
        },

        xAxis: {
            type: 'datetime'
        },
        yAxis: {
            labels: {
                formatter: function () {
                    return currencySymbol + this.axis.defaultLabelFormatter.call(this);
                }
            },

            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function () {
                return Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' + currencySymbol + Highcharts.numberFormat(this.y, 2);
            }
        },
        legend: {
            enabled: false
        },
        credits: {
            enabled: false
        },
        plotOptions: {
            series: {
                states: {
                    hover: {
                        lineWidthPlus: 0
                    }
                },
                lineWidth: 1,
                marker: {
                    enabled: false,
                    radius: 3
                }
            }
        },
        series: [{
            data: [{"y":93,"x":1412722800000},{"y":54,"x":1412722860000}],
            turboThreshold: 0
        }]
    });
});

Update 更新

I've updated the demo to include all suggestions I've received so far. 我已经更新了演示,以包含我目前收到的所有建议。 Disabling animations helped a bit, but the page is still very sluggish in Firefox (which is the main browser I'm targeting). 禁用动画有点帮助,但Firefox中的页面仍然非常缓慢(这是我目标的主要浏览器)。 I've started a bounty in the hope of attracting further suggestions. 我已经开始获得赏金,希望能够吸引更多的建议。

Here you can find FAQ answering your question. 在这里,您可以找到回答您问题的常见问题。

Additional note: Big performance boost you will get while disabling tooltip. 附加说明:在禁用工具提示时,您将获得巨大的性能提升。

Or just use Highstock, which has implemented dataGrouping , for example chart with 52k of points . 或者只使用已经实现了dataGrouping ,例如带有52k点的图表

I have found that animation can impact chart load times for large data sets. 我发现动画可以影响大型数据集的图表加载时间。 Try disabling animation: 尝试禁用动画:

plotOptions: {
    series: {
        animation:false,
        states: {
            hover: {
                lineWidthPlus: 0
            }
        }
    }
},

I have a suggestion, but I dont know if you like this. 我有一个建议,但我不知道你是否喜欢这个。 I needed charts with multiple axis and every axis has 1440 datapoints (they can only be 0 or 1 in my case) and they work fine. 我需要有多轴的图表,每个轴有1440个数据点(在我的情况下它们只能是0或1)并且它们工作正常。 What I had to do for this is to change the x-axis datatype and generate the date 'manualy'. 我必须做的是更改x轴数据类型并生成日期'manualy'。

Create categories on the x-axis with the date: 使用日期在x轴上创建类别:

xAxis: {
    categories: ['00:00', '00:01', '00:02', '00:03',  ..., '23:59']

Then every datapoint is ordered the same as the category: 然后每个数据点的排序方式与类别相同:

series: [{
    data: [1, 1, 1, 1, 1, 1, ..., null]

I know this is messy but when you do this you can reduce the data array to just the y-axis value and the rendering takes less time. 我知道这很麻烦,但是当你这样做时,你可以将数据数组减少到只有y轴值,并且渲染花费的时间更少。 See JSFiddle. 见JSFiddle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM