在zoomType上空白的Highcharts图表:'x'区域范围缩放?

时间:2013-07-25 17:13:36

标签: javascript html charts highcharts

好的,我有一张Highcharts图表,可以正确显示数据库中的数据;但是当我放大时,图表会变成空白吗?

这是图表HTML:

<div class="content" id="content"></div>

以下是图表的Javascript代码:

$(function () {
        $('#content').highcharts({
            chart: {
                zoomType: 'x',
                backgroundColor:'transparent'
            },
            credits: {
                enabled: false
            },
            title: {
                text: 'Players Online'
            },
            subtitle: {
                text: document.ontouchstart === undefined ?
                    'Click and drag in the plot area to zoom in' :
                    'Drag your finger over the plot to zoom in'
            },
            xAxis: {
                type: 'datetime',
                maxZoom: 3600000, // 1 hour
                title: {
                    text: null
                }
            },
            yAxis: {
                title: {
                    text: 'Players Online'
                }
            },
            tooltip: {
                enabled: false
            },
            legend: {
                enabled: false
            },
            plotOptions: {
                area: {
                    allowPointSelect: false,
                    fillColor: {
                        linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
                        stops: [
                            [0, Highcharts.getOptions().colors[0]],
                            [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
                        ]
                    },
                    lineWidth: 1,
                    marker: {
                        enabled: false
                    },
                    shadow: false,
                    states: {
                        hover: {
                            lineWidth: 1,
                            enabled: false
                        }
                    }
                }
            },
            series: [{
                type: 'area',
                data: [<?php echo join($data, ',') ?>]
                //This is displayed correctly in Javascript, so the issue isn't in my PHP
            }]
        });
    });

我在这里做些蠢事吗?似乎无法找到图表的原因变成空白。 :/

1 个答案:

答案 0 :(得分:5)

我通过Highcharts API文档找出了问题所在。

我知道所有图表类型都有一个名为'cropThreshold'的属性,这里是Highcharts API的链接,解释了它的详细信息: http://api.highcharts.com/highcharts#plotOptions.area.cropThreshold

但总结一下;如果您显示超过300个点(cropThreshold默认为300),则在放大时,您的图表将变为空白。要更正此问题,您可以将以下内容添加到图表配置中:

area: {
           cropThreshold: 500 <- //Vary this. I display 500 points on my chart in
                                 //total and so a value of 500 allows zooming to
                                 //work at all levels. This will vary for you
                                 //depending on how many points you plot.
      }