简体   繁体   English

线系列图在调整大小时出错 - highcharts

[英]Line series graphs gives error on resizing - highcharts

I have used highcharts single line series graph .我使用了 highcharts单线系列图 It seems to work all fine but when I resize the page (just to check responsiveness or just it on mobile).它似乎一切正常,但是当我调整页面大小时(只是为了检查响应性或只是在移动设备上)。 The values disappear.值消失。 I can see error in console logs.我可以在控制台日志中看到错误。

在此处输入图片说明

That's how I generate the chart这就是我生成图表的方式

Highcharts.stockChart('nav-chart', {

 tooltip: {
        pointFormat:"{point.y:.3f}\u20ac"
  },
  chart: {
    type: 'line',
    zoomType: 'x',
    pinchType: 'x',
    panning: false,
    <?php if (is_front_page()){ ?>
    height: 700,
    <?php } else { ?> 
    height: 500, 
    events: {
      load: updateLegendLabel 
    }    
    <?php } ?> 
  },

updateLegendLabel has some computation that generates the labels. updateLegendLabel有一些生成标签的计算。

 var chrt = !this.chart ? this : this.chart;
  chrt.update({
    legend: {
      useHTML: true,
      symbolPadding: 0,
      symbolWidth: 0,
      symbolHeight: 0,
      symbolRadius: 0,    
      labelFormatter: function() {


        var lastVal = this.yData[this.yData.length - 1],
          chart = this.chart,
          xAxis = this.xAxis,
          points = this.points,
          avg = 0,
          counter = 0,
          min, max;
... there is some business logic down there

points var becomes null when I resize the page.当我调整页面大小时, points var 变为 null。 Why is that so?为什么呢? Do I need to reupdate dataset or what?我需要重新更新数据集还是什么?

Nesting Server and Client side logic is not good.嵌套服务器端和客户端逻辑不好。 Better is to seperate logic using like this.更好的是使用这样的分离逻辑。 Bellow one is just for idea not a exact code.波纹管一个只是为了想法而不是一个确切的代码。 But can be fixed if you provide complete code separating your server logic from client side logic.但是,如果您提供将服务器逻辑与客户端逻辑分开的完整代码,则可以修复。

<script>
//before graph area started
var dataA = '<?php echo $dataA;?>';
var dataB = '<?php echo $dataB;?>';
//graph logic started
// your graph code which can use above variables
// but the variable need to be available can be evaluated from your draw script.

</script>

then use these variables in your graph script.然后在图形脚本中使用这些变量。 Because on resizing of browser, graph is redrawing and its looking data is not available when graph is redrawing.因为在调整浏览器大小时,图形正在重绘,并且在图形重绘时其查看数据不可用。 But if above logic will be used then data will be available on every redraw但是如果使用上述逻辑,那么每次重绘时数据都可用

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

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