gpt4 book ai didi

javascript - 在 Highcharts 中格式化工具提示数字

转载 作者:可可西里 更新时间:2023-11-01 02:29:04 25 4
gpt4 key购买 nike

我使用 tooltip.pointFormat 在工具提示中呈现附加数据。不幸的是,只有 point.x 使用千位分隔符正确格式化。

jsFiddle

$(function () {
Highcharts.setOptions({
global: {
useUTC: false,
},
lang: {
decimalPoint: ',',
thousandsSep: '.'
}
});
$('#container').highcharts({
xAxis: {
type: 'datetime'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.y}</b><br/>' + 'Count: <b>{point.count}</b><br/>',
shared: true
},
series: [{
data: [{
y: 20009.9,
count: 20009.9
}, {
y: 10009.9,
count: 20009.9
}, {
y: 40009.9,
count: 20009.9
}],
pointStart: Date.UTC(2010, 0, 1),
pointInterval: 3600 * 1000 // one hour
}]
});
});

最佳答案

找到答案 here .

Numbers are formatted with a subset of float formatting conventions from the C library funciton sprintf. The formatting is appended inside the variable brackets, separated by a colon. For example:

  • Two decimal places: "{point.y:.2f}"
  • Thousands separator, no decimal places: {point.y:,.0f}
  • Thousands separator, one decimal place: {point.y:,.1f}

因此在括号内使用 :,.1f 将正确格式化数字。

tooltip: {
pointFormat: '{series.name}: <b>{point.y}</b><br/>' + 'Count: <b>{point.count:,.1f}</b><br/>',
shared: true
}

jsFiddle

关于javascript - 在 Highcharts 中格式化工具提示数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27144967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com