Billboard.js的每个数据系列自定义标签

发布于 2025-02-04 10:07:49 字数 1042 浏览 2 评论 0原文

是否可以在Billboard.js中为每个数据系列应用自定义标签?与使用该系列中数据点的值,ID或索引相反?

我一直在使用以下Billboard.js文档进行参考: https://naver.github.io/billboard.js/release/release/latest/doc/doc/options.html#.data%25e2%2580%2580%25a4labels

https://naver.github.io/billboard.js/demo/#data.datalabelformat“ rel =“ nofollow noreferrer”> https://naver.github.github.io/billboard.js/demo/demo/demo/#datalabelformat

data: {
  labels: true,

  // or set specific options
  labels: {
   format: function(v, id, i, j) {
    ...
    // to multiline, return with '\n' character
    return "Line1\nLine2";
   },

   // it's possible to set for each data
   format: {
    data1: function(v, id, i, texts) { ... },
    ...
    },
  }
}

在上面的片段中,文本被描述为“整个相应数据系列的文本标签的数组”。但是参数似乎是空的,我不确定如何传递文本标签。例如,我正在处理包括城市,国家的数据。是否可以让传奇/瓷砖=城市和标签=乡村。

Is it possible to apply a custom label for each data series in billboard.js? As opposed to using the value, id, or index of the data point in the series?

I've been using the following billboard.js documentation for reference: https://naver.github.io/billboard.js/release/latest/doc/Options.html#.data%25E2%2580%25A4labels

https://naver.github.io/billboard.js/demo/#Data.DataLabelFormat

data: {
  labels: true,

  // or set specific options
  labels: {
   format: function(v, id, i, j) {
    ...
    // to multiline, return with '\n' character
    return "Line1\nLine2";
   },

   // it's possible to set for each data
   format: {
    data1: function(v, id, i, texts) { ... },
    ...
    },
  }
}

In the above snippet, texts is described as "the array of whole corresponding data series' text labels". But the parameter seems empty and I'm not sure how to pass in an array of text labels. For example, I'm working with data that includes a city, Country. Would it be possible to have the legend/tile = city and the label = country.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空心↖ 2025-02-11 10:07:49

您的问题帮助我解决了自己的问题。这就是我的方式:

labels : {
 format: {
    "data1": function(v, id ,i, j) { return i ==10 ?  "Label of 10th item in array data1" : "";},
    "data2": function(v, id ,i, j) { return i ==11 ?  "Label of 11th item in array data2" : "";},
    "data3": function(v, id ,i, j) { return i ==11 ?  "Label of 10th item in array data3" : "";},
    },
   } 

Your question helped me to deal with my own problem. Here is how I went about it:

labels : {
 format: {
    "data1": function(v, id ,i, j) { return i ==10 ?  "Label of 10th item in array data1" : "";},
    "data2": function(v, id ,i, j) { return i ==11 ?  "Label of 11th item in array data2" : "";},
    "data3": function(v, id ,i, j) { return i ==11 ?  "Label of 10th item in array data3" : "";},
    },
   } 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文