简体   繁体   English

highcharts图中的导航器不起作用

[英]Navigator in highcharts graph does not work

The rest of the chart functions correctly, and the navigator updates when I change the time scale, but resizing the navigator and scrolling left/right doesn't do anything (doesn't update the graph). 图表的其余部分正常运行,并且当我更改时间刻度时,导航器会更新,但是调整导航器的大小并向左/向右滚动不会执行任何操作(不会更新图形)。

在此处输入图片说明

To initialise the graph I do this: 为了初始化图形,我这样做:

Highcharts.stockChart('highchartLineChart', {
    title: {
        text: 'MyTitle'
    },
    subtitle: {
        text: ''
    },
    xAxis: {
        title: {
            enabled: true,
            text: 'Time (days)'
        },
        type: 'datetime',
    },
    yAxis: {
        title: {
            text: 'Value'
        },
    },
    navigator: {
        enabled: true,
        series: {
            id: 'navigator',
        }
    },
    series: []
});

Then I have an ajax method to populate it, which looks like this: 然后,我有一个ajax方法来填充它,如下所示:

var highchartLineData = [];

for (var i = 0; i < result.length; i++) {

    var parsedDate = new Date(result[i].MyDate.match(/\d+/)[0] * 1);

    var lineItem = {
        x: parsedDate,
        y: parseFloat(result[i].Value)
    };

    highchartLineData.push(lineItem);
}

 $('#highchartLineChart').highcharts().addSeries({
     name: "My Chart",
     data: highchartLineData
 });

Then I tried adding this, just playing around with various attempts to fix it 然后我尝试添加此内容,只是尝试进行各种尝试来修复它

var nav = $('#highchartLineChart').highcharts().get('navigator');
nav.setData(highchartLineData);
$('#highchartLineChart').highcharts().xAxis[0].setExtremes();

However it did not work. 但是它没有用。 Although you can drag the navigator left and right, nothing updates. 尽管可以左右拖动导航器,但不会更新任何内容。 Sometimes it breaks it and the top graph disappears, but it comes back if you press 1m 3m etc. 有时它会破坏它,并且顶部图形消失,但是如果按1m 3m等,它将返回。

There are no errors in the console. 控制台中没有错误。 Any ideas? 有任何想法吗?

In your code you do the following operation: 在您的代码中,执行以下操作:

var parsedDate = new Date(result[i].MyDate.match(/\d+/)[0] * 1);

var lineItem = {
    x: parsedDate,
    y: parseFloat(result[i].Value)
};

Setting x to be a Date object. x设置为Date对象。

According to Highcharts API on x values (for a line) it should be in milliseconds. 根据Highcharts API的x值(对于一行),该值应以毫秒为单位。

x: Number x:数字

The x value of the point. 点的x值。 For datetime axes, the X value is the timestamp in milliseconds since 1970. 对于日期时间轴,X值是自1970年以来的时间戳(以毫秒为单位)。

So if instead you would do the following: 因此,如果您改为执行以下操作:

var lineItem = {
    x: result[i].MyDate.match(/\d+/)[0] * 1,
    y: parseFloat(result[i].Value)
};

it should work. 它应该工作。 (Assuming result[i].MyDate.match(/\\d+/)[0] * 1 gives you the time in milliseconds. (假设result[i].MyDate.match(/\\d+/)[0] * 1为您提供时间,以毫秒为单位。

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

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