【问题标题】:Highcharts series showing different data for 'column' and 'line' chartHighcharts 系列显示“柱形”和“折线”图表的不同数据
【发布时间】:2019-07-09 13:31:49
【问题描述】:

我有一个带有两个 Y 轴的图表。两者都是第一个折线图,一切正常。但是当我将它更改为一个 Y 轴项目的柱形图时,图表以不同的方式绘制。似乎缺少一些要点。我有一个用于在“列”和“折线”图表之间切换的按钮。单击按钮后,它会显示不同类型的图形,即使两者的数据相同。这是我的javascript,

$.getJSON('https://api.myjson.com/bins/whjvj', function (dataSeries2) {
  $.getJSON('https://api.myjson.com/bins/dfoin', function (dataSeries1) {
    $('#container').highcharts('StockChart', {
      yAxis: [{
          height: 250,
          gridLineWidth: 1,
          title: {
            text: 'series 1',
            style: {
              color: '#3eca4f',
            },
          },
        },
        {
          title: {
            text: 'series 2',
            style: {
              color: '#888f94',
            },

          },
          top: 300,
          height: 100,
          offset: 0,
        },
      ],
      series: [{
          name: 'Series 1',
          yAxis: 0,
          type: 'line',
          data: dataSeries1,
        },

        {
          data: dataSeries2,
          name: 'Series',
          type: chartTypeRenew,
          yAxis: 1,
        },
      ],

    });


  });
});

And here is the fiddle of the same

谁能帮我解决这个问题?提前致谢。

【问题讨论】:

    标签: javascript charts highcharts


    【解决方案1】:

    该问题是由dataGrouping 引起的。默认情况下,approximation 与 column('sum')和 line('average')不同。您可以禁用dataGrouping 或设置相同的approximation。

    plotOptions: {
        series: {
            dataGrouping: {
                approximation: 'average'
            }
        }
    },
    

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

    API 参考: https://api.highcharts.com/highstock/series.column.dataGrouping.approximation

    文档: https://www.highcharts.com/docs/advanced-chart-features/data-grouping

    【讨论】:

    • 感谢您的回答。如您所说,问题出在 dataGrouping 上。我为 dataGrouping 设置了单位,一切都解决了。
    【解决方案2】:

    当您更改系列类型时,数据分组也会发生变化,因此点的近似值会有所不同。如果您将数据分组强制为“周”,它会显得更加相似(尽管对于其他一些时间间隔可能会很奇怪)。

    将此添加到每个系列以强制“周”数据分组(JSFiddle):

    dataGrouping: {
        units: [[
            'week',
            [1]]
        ]
    }
    

    或see the documentation了解更多详情。

    【讨论】:

    • 谢谢你的朋友。您的回答帮助我解决了问题。
    猜你喜欢
    • 1970-01-01
    • 2014-06-11
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多