简体   繁体   English

Highcharts - 如何从提供的 JSON 数据中获取价值以在 xAxis 或工具提示上使用

[英]Highcharts - How to get value from provided JSON data to use on xAxis or tooltip

im trying to create chart on web using javascript on JSP page.我试图在 JSP 页面上使用 javascript 在 web 上创建图表。 I found highcharts and it seems good.我找到了highcharts,看起来不错。 I try to use it, and was wondering how to get value from my series of data and show it on tooltips and xaxis of the chart as show in screenshot below.我尝试使用它,并且想知道如何从我的一系列数据中获取价值并将其显示在图表的工具提示和 xaxis 上,如下面的屏幕截图所示。 Screenshot截屏

do anyone have idea how to achieve that ?有人知道如何实现吗? so far, i could only get the "name" attribute using "this.series.name", but i couldn't get value from the data, i want to get data period "01 Jun 2022 - 05 Jun 2022".到目前为止,我只能使用“this.series.name”获取“name”属性,但我无法从数据中获取价值,我想获取数据周期“2022 年 6 月 1 日 - 2022 年 6 月 5 日”。

below is my series of data resulted from SQL select :下面是我从 SQL select 得到的一系列数据:

{"data": [
   ["01 Jun 2022 - 05 Jun 2022",2409],
   ["06 Jun 2022 - 12 Jun 2022",2722],
   ["13 Jun 2022 - 19 Jun 2022",2660]
 ]
,"name":"Unique Users"}

From above example, i can get 2409 using "this.y" , but no idea how to get "01 Jun 2022 - 05 Jun 2022" and show it on tooltip and xaxis value.从上面的示例中,我可以使用“this.y”获得 2409,但不知道如何获得“2022 年 6 月 1 日 - 2022 年 6 月 5 日”并将其显示在工具提示和 xaxis 值上。 Thanks.谢谢。

Inside tooltip.formatter you can logs this object and look how it's build.tooltip.formatter 中,您可以记录这个对象并查看它是如何构建的。

let JSON = [
  ["01 Jun 2022 - 05 Jun 2022", 2409],
  ["06 Jun 2022 - 12 Jun 2022", 2722],
  ["13 Jun 2022 - 19 Jun 2022", 2660]
];

let chart = Highcharts.chart('container', {
  series: [{
    data: JSON
  }],
    tooltip: {
        formatter: function(){
            console.log(this);
            return this.key
        }
    }
});

Demo: https://jsfiddle.net/BlackLabel/g03j9etv/2/演示: https ://jsfiddle.net/BlackLabel/g03j9etv/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM