给highcharts坐标设值问题
$(function () {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container3',
plotBorderWidth: 1,
zoomx:true,
type: 'line'
},
title: {
text: null
},
credits:{
enabled:false,
position: {
align: 'left',
x: 350,
verticalAlign: 'bottom'
}
},
legend: {
enabled:true
},
xAxis: {
type: 'datetime',
min:minDate, //0表示1月 以此类推
max:maxDate,
tickInterval :30*24*3600*1000,//X轴点间隔
labels: {
align: 'left',
formatter: function() {
return Highcharts.dateFormat('%Y%m%d', this.value);
}
}
},
yAxis: [
{
lineWidth:1,
// gridLineColor: 'red',
gridLineDashStyle: 'shortdash',
max:maxYield*100,
min:-maxYield*100,
opposite: true,
tickInterval:(maxYield*100/3),
title: {
text: null
},
labels: {
formatter: function() {
return this.value +'%';
}
}
},
{
lineWidth:1,
// gridLineColor: 'red',
gridLineDashStyle: 'shortdash',
max:1500,
min:-1500,
//opposite: true,
//tickInterval:500,
title: {
text: null
},
labels: {
formatter: function() {
return this.value ;
}
}
}
],
tooltip: {
formatter: function() {
return this.series.name+'<br/><strong>日期:</strong>'+
Highcharts.dateFormat('%Y%m%d', this.x) +'<strong>收益率:</strong> '+ this.y+'%' ;
}
},
plotOptions: {
line: {
dataGrouping: {
enabled: false
}
},
series: {
lineWidth:1,
marker: {
radius: 1 //鼠标接触时 显示点的大小
}
}
},
series: strategys
});
});
不是特别理解,是想在0做个分割线吗?如果是:
yAxis: {
plotLines: [{
width: 2,
value: 0,
id: 'plotline-1'
}]
},
yAxis: [
{
lineWidth:1,
// gridLineColor: 'red',
gridLineDashStyle: 'shortdash',
max:maxYield*100,
min:-maxYield*100,
opposite: true,
tickInterval:(maxYield*100/3),
title: {
text: null
},
labels: {
formatter: function() {
//注意改的是这里!!!!!!
if (this.value >0) {
return '<span style="fill: red;">' + this.value +'%'; + '</span>';
else if(this.value <0){
return '<span style="fill: green;">' + this.value +'%'; + '</span>';
} else {
return this.value +'%';
}
}
}
},
{
lineWidth:1,
// gridLineColor: 'red',
gridLineDashStyle: 'shortdash',
max:1500,
min:-1500,
//opposite: true,
//tickInterval:500,
title: {
text: null
},
labels: {
formatter: function() {
//注意改的是这里!!!!!!
if (this.value >0) {
return '<span style="fill: red;">' + this.value; + '</span>';
else if(this.value <0){
return '<span style="fill: green;">' + this.value; + '</span>';
} else {
return this.value;
}
}
}
}
],