我正在为一个项目使用带有可拖动点插件的Highcharts JS图表库。我可以设置我的数组值,并使它们生成良好。但是,当我试图通过向上或向下拖动点来更改任何给定数组元素的Y值时,控制台会将该元素返回为未定义。有什么想法吗?
代码:
drag: function (e) {
// Returning false stops the drag and drops. Example:
$('#drag').html('Dragging <b>' + this.series.name + '</b>, <b>' + this.category + '</b> to <b>' + Highcharts.numberFormat(e.newY, 0) + '</b>');
},
drop: function () {
$('#drop').html('In <b>' + this.series.name + '</b>, <b>' + this.category + '</b> was set to <b>' + Highcharts.numberFormat(this.y, 0) + '</b>');
console.log( array.map(function(c) { return c[1]; }) );
}
另一个问题是Y值不是整数,所以如果有人知道如何将数组元素四舍五入为可以工作的整数,则
更新点后,格式从[x_value, y_value]
更改为:{x: x_value, y: y_value}
。因此,对于更新的点,使用c.y
而不是c[1]
。由于使用了这两种格式,您需要检查使用哪种格式。