1. 程式人生 > >Highcharts圖表學習(二)

Highcharts圖表學習(二)

Highcharts相關功能設定,按鈕漢化、位置調整、縮放調整

var bottomWaterPointChart = function (div, stationKey, tagKey, name,tag_name,units) {

Highcharts.setOptions({
lang: {
printChart: '列印圖表',
downloadJPEG: '下載 JPEG 檔案',
downloadPDF: '下載 PDF   檔案',
downloadPNG: '下載 PNG  檔案',
downloadSVG: '下載 SVG  檔案',
downloadCSV: '下載 CSV  檔案',
downloadXLS: '下載 XLS   檔案',
viewData: '檢視資料表格',
resetZoom:'返回' //將原有的功能進行漢化處理
},
global: {
useUTC: false
}

});

$('#' + div).highcharts({
chart: {
type: 'spline',
zoomType: 'x',//圖表縮放設定,隨x縮放,隨y軸縮放,隨x、y一起縮放
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
resetZoomButton: {//返回按鈕進行位置調整,使其位置合適
position: {
align: 'right', // by default
verticalAlign: 'top', // by default
x: -100,
y: 0
},
relativeTo: 'chart'
},
// 取消邊框和背景
borderColor: '#fff',
//borderWidth: 2,
//borderRadius: 10,
backgroundColor: null
},
title: {
text: name + '一天曲線',
style: { 'color': '#333', "text-shadow": "1px 1px 1px rgba(0,0,0,0.5)" },
margin: 1
},
subtitle: {
text: ''
},
xAxis: [{

type: 'datetime',
tickPixelInterval: 150,
tickColor: '#333',
tickWidth: 1,
//刻度間隔(1小時)
tickInterval: 3 * 3600 * 1000,
lineColor: '#333',
labels: {

style: {
color: '#333'
}
},
// opposite: true,--
opposite: false,
plotLines: [{ color: '#333' }]
}],
yAxis: [{
labels: {
format: '{value}m',
style: {
color: '#333'
}
},
lineColor: '#FCFFC5', tickColor: '#333',
title: {
text: tag_name,
style: {
color: '#333'
}
}
}, {
title: {
text: tag_name,
style: {
color: '#333'

}
},
labels: {
//format: '{value} mm',--
format: '{value}'+units,//++
style: {
color: '#333'
}
},
//reversed: true,--
reversed: false,
lineColor: '#333', tickColor: '#333',
opposite: true
}],
tooltip: {
//shared: true
shared: false,
formatter: function () {
return Highcharts.dateFormat('%H:%M', this.x) + '<br/><b>' + this.series.name + '</b>' + this.y;
}
},
legend: {
enabled: false
},
series: [{
name: tag_name,
color: '#4572A7',
type: 'line',
yAxis: 1,
//data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
tooltip: {
valueSuffix: units
}

}]
});
};