效果如上 , 废话不多说, 贴码:: jsp::::::<div id="container" style="height: 400px; min-width: 310px"></div>
js:: function xueyachart(){
var seriesOptions = [],
seriesCounter = 0,
names = ['舒张压','收缩压'];
function createChart() {
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 4
},
// rangeSelector: {
// buttonTheme: {
// display: 'none' // 不显示按钮
// },
//
// selected: 1,
// inputEnabled: false //不显示年份
// },
yAxis: {
labels: {
formatter: function () {
// 低血压:收缩压<90mmHg、舒张压<60mmHg
// 正常血压:收缩压<120mmHg、舒张压<80mmHg
// 正常高值:收缩压120~139mmHg、舒张压80~89mmHg;
// 1级高血压(轻度):收缩压140-159mmHg、舒张压90-99mmHg;
// 2级高血压(中度):收缩压160-179mmHg、舒张压100-109mmHg
// 3级高血压(重度):≥180 mmHg、 ≥110 mmHg
if(names[0]=='舒张压'){
if(this.value < 90){
return ''+ this.value + '低血压';
}
if(this.value <120){
return ''+ this.value + '正常血压';
}
if(this.value >= 120&&this.value<=139){
return ''+ this.value + '正常高值';
}
if(this.value >= 140&&this.value<=159){
return ''+ this.value + '1级高血压(轻度)';
}
if(this.value >= 160&&this.value<=179){
return ''+ this.value + '2级高血压(中度)';
}
if(this.value >= 180){
return ''+ this.value + '3级高血压(重度)';
}
}
else{
if(this.value < 60){
return ''+ this.value + '低血压';
}
if(this.value <80){
return ''+ this.value + '正常血压';
}
if(this.value >= 80&&this.value<=89){
return ''+ this.value + '正常高值';
}
if(this.value >= 90&&this.value<=99){
return ''+ this.value + '1级高血压(轻度)';
}
if(this.value >= 100&&this.value<=109){
return ''+ this.value + '2级高血压(中度)';
}
if(this.value >= 110){
return ''+ this.value + '3级高血压(重度)';
}
}
// return (this.value > 0 ? ' + ' : '') + this.value + '%';
}
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> <br/>',
valueDecimals: 2
},
series: seriesOptions
});
}
var arr = new Array(sousuoya,shuzhangya);
$.each(names, function (i, name) {
if(i==1)
seriesOptions[i] = {
color:'red',
name: name,
data: jQuery.parseJSON(arr[i])
};
else
seriesOptions[i] = {
color:'green',
name: name,
data: jQuery.parseJSON(arr[i])
};
seriesCounter += 1;
if (seriesCounter <= names.length) {
createChart();
}
});
} ::::
唯一要注意的便是 json格式 自己封装了一个方法来拼数据:: 可借鉴
function commonUtil (data){
var str=JSON.stringify(data);
while(str.indexOf('{')>=0){
str=str.replace('{','[')
}
while(str.indexOf('}')>=0){
str=str.replace('}',']')
}
while(str.indexOf('"')>=0){
str=str.replace('"','')
}
return str.toString();
}