【问题标题】:Highchart Time Data With Irregular Interval and Text具有不规则间隔和文本的 Highchart 时间数据
【发布时间】:2016-11-07 06:00:10
【问题描述】:

我试图对 Highchart Time 数据进行一些不规则间隔(样条不规则时间)的修改,例如 http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/spline-irregular-time/

所以,我想修改 UTC 数组以放置一些额外的文本数据。

我将数组更改为一个对象,并将原始示例的 UTD 数据放入变量“y”中,但没有成功。

提前致谢。

这是我修改后的代码:

$(function() {
Highcharts.chart('container', {
    chart: {
        type: 'spline'
    },
    title: {
        text: 'Snow depth at Vikjafjellet, Norway'
    },
    subtitle: {
        text: 'Irregular time data in Highcharts JS'
    },
    xAxis: {
        type: 'datetime',
        dateTimeLabelFormats: { // don't display the dummy year
            month: '%e. %b',
            year: '%b'
        },
        title: {
            text: 'Date'
        }
    },
    yAxis: {
        title: {
            text: 'Snow depth (m)'
        },
        min: 0
    },
    tooltip: {
        formatter: function() {
            return 'Extra data: <b>' + this.point.myData + '</b>';
        }
    },

    plotOptions: {
        spline: {
            marker: {
                enabled: true
            }
        }
    },

    series:

        [{
        name: 'Foo',


        data: [{
            y: [Date.UTC(2016, 7, 29), 1.0],
            myData: 'firstPoint'
        }, {
            y: [Date.UTC(2016, 9, 29), 2.0],
            myData: 'secondPoint'
        }, {
            y: [Date.UTC(2016, 9, 29), 3.18],
            myData: 'thirdPoint'
        }],

    }],     
});
});

【问题讨论】:

  • "我把数组改成对象,把原始例子的UTD数据放到变量"y"中没有成功。"当然不是,"y"需要是y 数据点值。你到底想用myData 值做什么?

标签: javascript highcharts


【解决方案1】:

点对象的格式无效,y 应该是数字,而不是数组。

    {
        x: Date.UTC(2016, 7, 29),
        y: 1.0,
        myData: 'firstPoint'
    }

示例:http://jsfiddle.net/reutw7gb/

还有一种将点配置为数组的可选方法。可以设置系列keys属性。

  keys: ['x', 'y', 'myData'],
  data: [
    [Date.UTC(2016, 7, 29), 1.0, 'firstPoint'],
    [Date.UTC(2016, 9, 29), 2.0, 'secondPoint'],
    [Date.UTC(2016, 9, 29), 3.18, 'thirdPoint']
  ],

示例:http://jsfiddle.net/reutw7gb/1/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多