我无法将图表的 y 轴最小刻度动态更新为 0。我尝试为我正在处理的所有类型的图表构建一个通用图表。有些图表有负值,所以我需要负轴和带百分比的柱形图,没有负轴。我在 javascript 代码中设置一个参数来查看它是否为百分比,然后根据它显示 y 轴的最小刻度。此外,工具提示必须是动态的,这是我无法实现的。我当前的方法中遗漏了一些东西 这是fiddle
$(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'
}]
});
});
这是分钟。 更新: http://jsfiddle.net/CaPG9/31/
像这样吗?
关于javascript - 在 highcharts 中动态更新 yAxis 最小值和工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26875747/