使用Highcharts按ID选择一个点 [英] Selecting a point by ID using Highcharts

查看:437
本文介绍了使用Highcharts按ID选择一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Highcharts,我如何使用它的ID选择一个点?例如,如果我使用以下代码创建图表:

  chart1 = new Highcharts.Chart({
图表:{
renderTo:'container',
type:'scatter'
},
title:{
text:'Fruit Consumption'
},
xAxis:{
categories:['Apples','Bananas','Oranges']
},
yAxis:{
title:{
text:'吃了水果'
}
},
系列:[{
name:'Jane',
data:[{
name:' Point1',
x:1,
y:2
},{
名称:'Point2',
x:2,
y:5
}]
},{
name:'John',
data:[5,7,3]
}]
});
});

工具提示告诉我,当我将鼠标悬停在某个点上时,该id是什么。但是,我无法弄清楚这一点的语法。我知道 chart1.series [0] .name 返回 Jane。此外,
chart1.series [0] .data [0] .name 返回 point1`有没有简单的方法,我可以只需要选择点并改变颜色只知道'point1'?



我想知道是否有一种更有效的方法,而不是每次循环遍历所有点。

解决方案

您可以为每个要设置的点设置一个 id 得到。

 系列:[{
name:'Jane',
data:[ {
'name':'Point1',
'id':'point1',
'x':1,
'y':2
}, {
'name':'Point2',
'id':'point2',
'x':2,
'y':5
}]
},{
name:'John',
data:[5,7,3]
}]

然后您可以通过以下代码获得该点。

  //假设图表是你的图表var 
chart.get('point1');

id 你可以简单地循环thrue points 来比较你想要找到的 name 点名称



参考


Using Highcharts, how can I select a point using it's id? For example, if I create a chart using the following code:

 chart1 = new Highcharts.Chart({
         chart: {
            renderTo: 'container',
            type: 'scatter'
         },
         title: {
            text: 'Fruit Consumption'
         },
         xAxis: {
            categories: ['Apples', 'Bananas', 'Oranges']
         },
         yAxis: {
            title: {
               text: 'Fruit eaten'
            }
         },
         series: [{
            name: 'Jane',
            data: [{
                name: 'Point1',
                x: 1,
                y: 2
            }, {
                name: 'Point2',
                x: 2,
                y: 5
            }]
         }, {
            name: 'John',
            data: [5, 7, 3]
         }]
      });
   });

The tooltip tells me that when I hover over a point, what the id is. However, I can't figure out the syntax to identify that point. I know that chart1.series[0].name returns Jane. Also, chart1.series[0].data[0].namereturnspoint1` Is there an easy way that I can just select the point and change the color knowing only 'point1'?

I'm wondering if there is a more efficient way other than looping through all of the points each time.

解决方案

You can set an id for each point you want to get.

series: [{
    name: 'Jane',
    data: [{
        'name': 'Point1',
        'id': 'point1',
        'x': 1,
        'y': 2
    }, {
        'name': 'Point2',
        'id': 'point2',
        'x': 2,
        'y': 5
    }]
}, {
    name: 'John',
    data: [5, 7, 3]
}]

Then you can get the point by the following code.

// assuming that chart is your chart var
chart.get('point1');

demo

Or if you don't want to set an id you can simple loop thrue points to compare the name you want to find with the point name.

Reference:

这篇关于使用Highcharts按ID选择一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆