highcharts設定總結
阿新 • • 發佈:2018-12-23
var chart = Highcharts.chart('container', {
chart: {
type: 'line'
},
title: { //標題,如不需要可以置空
text: ''
},
subtitle: { //副標題
text: ''
},
xAxis: {
labels: {
enabled: false //是否顯示x軸的標籤
},
type: 'datetime', //如果x軸是時間,設定該項可以進行格式轉換
},
yAxis: {
title: {
text: '' //y軸標題
},
labels: {
enabled: false //是否顯示y軸的標籤
}
},
legend: { //圖例設定
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
width:0,
enabled: false, //是否顯示
},
navigation:{ //導航,下載儲存為圖片的地方
buttonOptions:{
enabled:false
}
},
credits:{
enabled:false //版權資訊是否顯示
},
tooltip:{ //資料提示框
backgroundColor:'#FFFFFF',
borderColor:'#cccccc',
shared: true,
useHTML: true,
formatter:function() { //通過該方法可以返回自定義的提示內容,要同時設定上面兩項
var points = this.points;
var _time = this.x;
//時間格式化
_time = new Date(_time);
var year = _time.getFullYear();
var month = _time.getMonth()+1;
var date = _time.getDate();
year = year.toString().substr(2,2);
var str_time = [date,month,year].join('/');
var header = '<b style="margin:10px 0;display:block;font-weight:700">'+ str_time +'</b><table>';
var body = '';
var footer = '</table>';
for(var i=0;i<points.length;i++){
var _color = points[i].series.color;
var _y = points[i].y;
var _name = points[i].series.name;
//單獨給某一項設定百分比顯示
if(points[i].series.name == "CTR"){
body+= '<tr><td style="width:30px;height:1px;background:'+ _color +';display:inline-block;margin-right:10px"></td><td style="color:'+ _color +'">'+ _name +': </td><td style="text-align: left"><b id="point_name">'+ _y +'%</b></td></tr>';
} else {
body+= '<tr><td style="width:30px;height:1px;background:'+ _color +';display:inline-block;margin-right:10px"></td><td style="color:'+ _color +'">'+ _name +': </td><td style="text-align: left"><b id="point_name">'+ _y +'</b></td></tr>';
}
}
return header+body+footer;
},
xDateFormat: '%d/%m/%Y',
},
plotOptions: {
series: { //設定標記點的樣式
label: {
connectorAllowed: false
},
marker:{
enabled:false,
symbol:'circle', //這裡可以設定資料點的全域性樣式,統一為某一種
radius:5,
},
negativeColor:'#fff',
allowPointSelect:false,
cursor: 'pointer',
states:{
hover:{
halo:'false' //這裡設定滑鼠移到資料點上時資料點不顯示外層圓圈
}
},
//處理x軸的時間格式,要配合xAxis下面的type:'datetime'使用
pointStart: Date.UTC(2017, 0, 1),
pointInterval: 24 * 3600 * 1000,
}
},
series: [{ //設定相關資料及其他資訊
name: 'Clicks',
data: [13, 22, 27, 21, 22, 35, 41, 41,21],
color:'#4d90fe',
}, {
name: 'Impressions',
data: [24, 24, 29, 20, 32, 30, 38, 40,32],
color:'#dd4b39'
}, {
name: 'CTR',
data: [11.23, 17.34, 16.12, 19.43, 20.54, 24.65, 28.34, 30.32,42.54],
color:'#ff9900'
}, {
name: 'Position',
data: [29, 31, 39, 12, 15, 22, 34, 39,28],
color:'#109618'
}],
responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom'
}
}
}]
}
});