Javascript 在highcharts中动态更新yAxis最小值和工具提示
我无法将图表的yaxis min tick动态更新为0。我试图为我正在处理的所有类型的图表构建一个通用图表。一些图表有负值,所以我需要带百分比的负轴和柱状图,没有负轴。我在javascript代码中设置了一个参数,查看它是否为百分比,然后根据它显示y轴的最小刻度。此外,工具提示必须是动态的,这是我无法实现的。在我目前的做法中,我遗漏了一些东西 这是Javascript 在highcharts中动态更新yAxis最小值和工具提示,javascript,jquery,charts,highcharts,Javascript,Jquery,Charts,Highcharts,我无法将图表的yaxis min tick动态更新为0。我试图为我正在处理的所有类型的图表构建一个通用图表。一些图表有负值,所以我需要带百分比的负轴和柱状图,没有负轴。我在javascript代码中设置了一个参数,查看它是否为百分比,然后根据它显示y轴的最小刻度。此外,工具提示必须是动态的,这是我无法实现的。在我目前的做法中,我遗漏了一些东西 这是 $(函数(){ var isPercent='真'; $(“#容器”)。高图({ 图表:{ 类型:“列” }, 亚克斯:{ 最小值:(isPerce
$(函数(){
var isPercent='真';
$(“#容器”)。高图({
图表:{
类型:“列”
},
亚克斯:{
最小值:(isPercent==='true'?0:null),
标签:{
格式:(isPercent=='true'?'{value}%':'{value}'),
}
},
工具提示:{
pointFormat:“{series.name}:{point.y:,.0f}”+(isPercent==='true'?'%':'')+”
},
系列:[{
名称:“1”,
数据:[10,31,100,89,92,12]
}, {
名称:‘2’,
数据:[90,69,0,11,8,88]
}, {
名称:‘3’,
数据:[90,69,0,-11,8,88],
类型:“行”
}]
});
});
这是最小值。已更新:
像这样?设置yAxis的最小值不会使数据改变。你应该处理你的数据。搜索数据中的负值并将其设置为0。如果isPercent为true,则我必须在值的末尾显示
%
,否则只需将数字保持原样,不带%
符号。pointFormat:“{series.name}:{point.y:,.0f}
”
$(function () {
var isPercent = 'true';
$('#container').highcharts({
chart: {
type: 'column'
},
series: [{
name: '1',
data: [10, 31, 100, 89, 92, 12]
}, {
name: '2',
data: [90, 69, 0, 11, 8, 88]
}, {
name: '3',
data: [90, 69, 0, -11, 8, 88],
type: 'line'
}]
},function(chart){
if(isPercent === 'true') {
chart.options.yAxis['min'] = 0;
console.log(chart.options.yAxis['min']);
}
});
});
$(function () {
var isPercent = 'true';
$('#container').highcharts({
chart: {
type: 'column'
},
yAxis:{
min : (isPercent === 'true' ? 0 : null),
labels:{
format:(isPercent === 'true' ? '{value}%' : '{value}'),
}
},
tooltip:{
pointFormat:'<span style="color:{series.color}">{series.name}</span>: <b>{point.y:,.0f}' + (isPercent === 'true' ? '%' : '') + '</b><br/>'
},
series: [{
name: '1',
data: [10, 31, 100, 89, 92, 12]
}, {
name: '2',
data: [90, 69, 0, 11, 8, 88]
}, {
name: '3',
data: [90, 69, 0, -11, 8, 88],
type: 'line'
}]
});
});