我试图减少图表上数据点之间的距离,代码来自高图示例
$(function () {
$(document).ready(function() {
Highcharts.setOptions({
global: {
useUTC: false
}
});
var chart;
$('#container').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 5,
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint([x, y], true, true);
}, 1000);
}
}
},
title: {
text: 'Live random data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 50 // here i wanted to decerease bu it does not work
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 0.1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{ // series with random data
name: 'Random data', // may be here
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -19; i <= 0; i++) {
data.push({
x: time + i * 1000,
y: Math.random()
});
}
return data;
})()
}]
});
});
});
有可能吗?我需要缩小xAxis或减少线上点之间的距离
答案 0 :(得分:1)
为了做你要问的事,你可以考虑:
1)使图表变小,使各个点更接近(参见http://jsfiddle.net/brightmatrix/Gq9X9/):
chart: {
vtype: 'spline',
width: 300, /* make this value anything you want */
animation: Highcharts.svg, // don't animate in old IE
marginRight: 5,
...
这与上面提到的@falconw建议类似。
2)在这个特定的实时示例中,更改数据的计算方式,以便每次更新图表时推出更多的点数(请参阅http://jsfiddle.net/brightmatrix/Fp5K4/):
series: [{
name: 'Random data',
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -19; i <= 0; i++) {
data.push({
/* made the multiplier larger so points are closer together */
x: time + i * 10000,
y: Math.random()
});
}
return data;
})()
}]
底线,无论是更改图表尺寸还是使数据“更密集”,所以点数更接近。我希望这会有所帮助。