【问题标题】:Highcharts chart going blank on zoomType: 'x' area range zoom?在 zoomType 上 Highcharts 图表变为空白:“x”区域范围缩放?
【发布时间】:2013-07-25 17:13:35
【问题描述】:

好的,我有一个 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
            }]
        });
    });

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

【问题讨论】:

  • 您是否按 x 升序对数据进行了排序?你能附上你的数据对象吗?
  • @SebastianBochan 我链接了使用图表的网站,以便您可以实时查看其中的数据。
  • 我打开了您的示例并通过 x 进行缩放工作正常,您使用哪种浏览器?
  • @SebastianBochan 啊,实际上是我在翻阅 Highcharts API 文档后自己找到了解决方案。我已经添加了答案。

标签: javascript html charts highcharts


【解决方案1】:

我在翻阅 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.
      }

【讨论】:

  • 我刚刚在API中看到,他们告诉如果超出cropthreshold的点将被削减到默认为300的cropThreshold大小,那么图表怎么会变成空白...... ?
  • @user2634485 这也是我对 API 的理解。但是,当我没有将cropThreshold 设置为高于我所拥有的点数时,图表会在放大时变为空白。可能是我拥有的特定配置的错误或我在某处的错误。从那以后我再也没有遇到过这种情况,所以我猜这是一个错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多