Add Flag based on button event

China☆狼群 提交于 2019-12-11 12:39:28

问题


series: [{

type: 'flags',
name: 'Flags on axis',

data: [{
x: Date.UTC(2011, 2, 1),
title: 'A'

}, {
x: Date.UTC(2011, 5, 1),
title: 'C'
}],

shape: 'squarepin'
}]

 $("#btnAddFlag").click(function () {

chart.series[0].setData(
{

x: Date.UTC(2011, 2, 1),
title: 'B'
});

});

Above code is part of highstock chart option and I want to add flag based on user event click. However I able to add the new point flag into the chart but the existing flags which title A and C will be missed out.

  1. how can I add the new flag into the chart with the existing flags ?

  2. On the other hand, I am able get the flag data but I'm unsure to generate the correct data structure and reinitialize the old and new flag data back into the chart.

Thank you.


回答1:


Use addPoint instead of setData.

http://api.highcharts.com/highstock#Series.addPoint()

$("#btnAddFlag").click(function () {
  chart.series[0].addPoint({
    x: Date.UTC(2011, 2, 1),
    title: 'B'
  });
});


来源:https://stackoverflow.com/questions/15740909/add-flag-based-on-button-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!