【发布时间】:2016-04-11 11:24:55
【问题描述】:
我制作了一个 Highstock 图表,但在缩放 yAxis 时遇到了问题。 我有一个 Button 和 2 个文本字段来获取轴的所需最小/最大值。使用 min:0, max: 100 效果很好。使用 min:0, max:80 则不会(图表中的最大值仍为 100)。 如果我使用鼠标进行缩放,它工作得很好(甚至最小:3.7 和最大 3.894 是可能的)。但是使用鼠标不是一个选项,因为在后面的 Diagramm 中会有 3 个 yAxes 单独缩放。
$(function () {
var seriesOptions = [],
seriesCounter = 0,
names = ['MSFT', 'AAPL', 'GOOG'];
/**
* Create the chart when all data is loaded
* @returns {undefined}
*/
function createChart() {
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 4
},
chart:{
zoomType: 'xy'
},
yAxis: [
{
labels: {
format: '{value}',
},
height: '100%',
opposite: false,
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
],
plotOptions: {
series: {
compare: 'percent'
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2
},
series: seriesOptions
},
function(chart){
$('#btn').click(function(){
var min = temp_min.value,
max = temp_max.value;
chart.yAxis[0].setExtremes((min),(max));
});
});
}
$.each(names, function (i, name) {
$.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=' + name.toLowerCase() + '-c.json&callback=?', function (data) {
if(seriesCounter==0){
seriesOptions[i] = {
name: name,
data: data,
yAxis: 0
};
} else {
seriesOptions[i] = {
name: name,
data: data,
yAxis: 0
};
}
// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
seriesCounter += 1;
if (seriesCounter === names.length) {
createChart();
}
});
});
});
另一个问题:是否也可以为 yAxis 设置滚动条? 谢谢你的帮助,帕特里克
【问题讨论】:
标签: max zooming highstock min axes