从系列点击事件中获取价值,并在图例上显示

时间:2018-05-05 13:40:19

标签: javascript highcharts

我想要做的是从click事件中获取价格(在这种情况下是y值),并且能够将其用作变量,以便在单击不同数据集时动态显示名称。下面的代码是我写的,显然不起作用。我能在这做什么?需要帮助〜

plotOptions: {
                    line: {

                    },
                    series: {
                          cursor: 'pointer',
                          point: {
                                events: {
                                      click: function (events) {
                                            var price = events.y;
                                      }
                                }
                          }
                    }
              },
              series: [{
                          name:'bank sold at price : ' + price,

                          data: [
                                [Date.UTC(2017, 5, 1), 29.74],
                                [Date.UTC(2017, 5, 2), 29.745],
                                [Date.UTC(2017, 5, 3), 29.735],
                                [Date.UTC(2017, 5, 5), 29.73],

1 个答案:

答案 0 :(得分:0)

更新plotOptions

  plotOptions: {
    series: {
      cursor: "pointer",
      point: {
        events: {
          click: function(events) {                    
            var chart = this.series.chart; //define charts 
            price = this.y;
            chart.series[0].update({ name: "bank sold at price :" + price }, false); //update chart series name
            chart.redraw(); //redraw charts

          }
        }
      }
    }
  },

demo