每當我將數據放入我的Highcharts圖表時,y軸上的類別都是動態的,並根據數據進行調整。我希望類別保持不變,我想要:類別:['1','10','100','1000','10000']沿着兩個軸。在Highcharts上做類別
是否有人知道如何使它們保持不變,而不管輸入的數據是什麼?
這是我的圖表,但我想沿底部和左側的數字來顯示1,10,100,1000,1000'
代碼:
<script type="text/javascript">
$(function() {
function newRandomColor() {
var color = [];
color.push((Math.random() * 255).toFixed());
color.push((Math.random() * 255).toFixed());
color.push((Math.random() * 255).toFixed());
color.push((Math.random()).toFixed(2));
var text = 'rgba(' + color.join(',') + ')';
console.log(text);
return text;
}
function newRandomData(n) {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -1 * n; i <= 0; i++) {
var color = newRandomColor();
data.push({
y:Math.random() * 90 + 60,
color: color,
fillColor: color
});
}
return data;
}
$('#chart5').highcharts({
chart: {
type: 'scatter',
marginRight: 130,
marginBottom: 35
},
title: {
text: 'Average vs Max Alarm Rates',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
title: {
text: 'Peak alarm rate/10 mins'
},
plotLines: [{
value: 0,
width: 1,
color: '#b51f2b'
}]
},
yAxis: {
title: {
text: 'Average alarm rate/10 mins'
},
plotLines: [{
value: 0,
width: 1,
color: '#b51f2b'
}]
},
tooltip: {
valueSuffix: ' alarms'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: [{
color: 'green',
name: 'Alarms',
data: newRandomData(40)
}]
}, function(chart) { // on complete
chart.renderer.image('images/alarmrategrid.png', 57, 41, 635, 248)
.add();
});
});
</script>
我嘗試添加類別,但它似乎沒有工作。
可以顯示圖表的代碼?通常您可以自定義沿每個軸的類別。 –
@SoftwareGuy已經完成了,歡呼:) –
好吧,您可能會知道,但是您正在使用散點圖,並且它沒有可用的類別選項。請參閱:http://www.highcharts.com/demo/scatter - 也許嘗試其他圖表類型(如果適用)? –