我使用 HighCharts 插件来绘制图表。但是我有一些麻烦:当图表为空时,我只看到 xAxis,而 yAxis 不显示。当图表不为空且有绘制图表的数据时,显示y轴。我找不到解决这个问题的方法。
function drawChart(jsonData) {
var rate = 20;
var is3Axis = $("#sel_charttype").val() == "1";
var options = {
chart: {
renderTo: 'chart',
defaultSeriesType: 'line',
margin: [50, 65, 50, 55],
backgroundColor: '#fff'
},
title: null,
xAxis: {
categories: jsonData.timeTicks
},
tooltip: {
enabled: true,
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
this.x + ': ' + this.y;
}
},
plotOptions: {
line: {
dataLabels: {
enabled: true,
style: {
fontSize: '13px'
},
x: 0,
y: -10
},
marker: {
symbol: 'circle'
}
}
},
legend: {
layout: 'horizontal',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 0,
floating: false,
shadow: false,
borderWidth: 0,
itemStyle: {
fontSize: '11px'
}
},
credits: {
enabled: false
}
};
if (is3Axis) {
options.yAxis = [
//primary axis
{
title: {
text: 'Amount'
},
gridLineColor: '#f1f1f1'
},
{
gridLineWidth: 0,
title: {
text: 'Total',
style: {
//color: '#89A54E'
}
},
opposite: true
}
];
options.series = jsonData.summary3AxisData;
} else {
// options.chart.margin[1] = 30;
options.yAxis = {
title: {
text: ''
},
gridLineColor: '#f1f1f1'
};
options.series = jsonData.summaryData;
}
if (chart)
$("#chart").html('');
chart = new Highcharts.Chart(options);
if (jsonData.url) {
$("#chart .highcharts-container").css("cursor", "pointer").click(function () {
window.open(jsonData.url, "_self");
});
}
}