点击图表时,出来的title 里面的值只能才能拿到呢? 因为这个值我需要赋值给实际值
我生成曲线用的方法
echartsClick(item_id){
console.log(item_id);
const _this=this;
const log=console.log;
let myChart =this.$echarts.init(document.getElementById('main'));
var optionFH = {
axisLine: {
show: false
},
// 控制网格线是否显示
splitLine: {
show: true
},
// 去除y轴上的刻度线
axisTick: {
show: false
},
title: {
left: 10,
show: true,
text: '',
textStyle: {
color: 'white',
fontSize: 16,
fontFamily: "微软雅黑",
}
},
tooltip: {
trigger: 'axis',
position:function(p){ //其中p为当前鼠标的位置
if(p[0]>250){
return [p[0] - 100, p[1] - 10];
}
if(p[0]<250){
return [p[0] + 10, p[1] - 10];
}
}
},
color: ["#02aac2","#f19f00","#5BD600","#AC6FFF","#C4EA79","#E9F3B5"], //设置图例的颜色必须用数组格式
legend: {
orient: 'horizontal',
right: 25,
top: 0,
data: ['实时巡检'],
itemWidth: 22, //图例宽度圆点
itemHeight: 15,
background: "#149f79",
textStyle:{
color:"white",//图例开启时的颜色。
fontSize:13,//图标上方点击按钮的文字大小
}
},
calculable: true,
xAxis: {
type: 'category',
boundaryGap: false,
splitLine: { //给x轴添加分割线
show: true,
lineStyle: {
color: '#35363B',
width: 1
}
},
axisLabel: {
show: true,
interval: 'auto',
textStyle: {
// color: '#35363B'
color: 'white'//字体颜色
}
//interval: Int //纵坐标的数据全部显示
},
axisLine:{
show: true,
lineStyle: {
// color: 'red'//x轴的颜色
color: 'white'//x轴的颜色
}
},
axisTick: {
show: false //是否显示坐标轴的刻度
},
data: [0]
//data: arrOne_FH
},
grid: { // 控制图的大小,调整下面这些值就可以,
x: 50,
top:20,//-----------------------------------------------------------------------------------
// width:300,//整体的宽度
// x2: 100,
// y2: 80,// y2可以控制 X轴跟Zoom控件之间的间隔,避免以为倾斜后造成 label重叠到zoom上
},
yAxis: {
type: 'value',
splitLine: { //给x轴添加分割线
show: true,
lineStyle: {
color: '#35363B',//里面线的颜色
width: 1
}
},
// name: "标单(元/吨)",
nameTextStyle: {
fontSize: 15,
color: '#a9a9a9'
},
axisLabel: {
show: true,
interval: 'auto',
inside: false,
// rotate: 90,
// margin: 8,
formatter: null,
showMinLabel: null,
showMaxLabel: null,
},
nameLocation: "end", //坐标轴名字的位置
// nameRotate:90,
axisLabel: { //坐标轴字体的颜色
show: true,
textStyle: {
// color: '#35363B'
color: 'white'//字体颜色
}
},
axisLine: { //是否显示y轴
show: true,
lineStyle: {
// color: 'red'//y轴的颜色
color: 'white'//y轴的颜色
}
},
axisTick: {
show: false //是否显示坐标轴的刻度
},
// max: function(value) {
// if(value.max<30){
// return Math.floor(value.max) + 5;
// }else if(value.max>=30&&value.max<=100){
// return Math.floor(value.max) + 10;
// }else if(value.max>100&&value.max<2000){
// return Math.floor(value.max) + 50;
// }else if(value.max>=2000){
// return Math.floor(value.max) + 100;
// }
// }
},
series: [
{
name: '实时巡检',//1号负荷
type: 'line',
symbol: 'none', //去除折线点
yAxisIndex: 0,
data:0,
itemStyle: {
normal: { //折线点的颜色,
color: function(params) {
var colorList = ["yellow"];
return colorList[params.dataIndex];
}
},
},
itemStyle: { //跟折线添加颜色
normal: {
lineStyle: {
color: "#02aac2"
}
},
},
}
]
};
myChart.setOption(optionFH);
axios.get(`/xunjian/api/task/getItemHistoryDataListByItemId/${item_id}`).then((response)=>{
log(response.data.data);
console.log(response.data.data);
var arrOne_FH = [];
var arrOne_FH_val = [];
let Onezhi;
for(var i in response.data.data){
// console.log(response.data.data[i].value);
var FHOne = response.data.data[i].recordTime.slice(11, 16);//x轴时间
var FHOne_val =response.data.data[i].value;
arrOne_FH.push(FHOne);
arrOne_FH_val.push(FHOne_val);
}
var resv = arrOne_FH.reverse();
arrOne_FH_val.reverse();
// optionFH.legend.data = [Onezhi]; //设置右上角的文字
optionFH.xAxis.data = resv;
// optionFH.series[0].name =Onezhi;
optionFH.series[0].data = arrOne_FH_val;
myChart.setOption(optionFH,true);
window.onresize = function () {
//重置容器高宽
myChart.resize();
};
})
}
在线等,如果拿到title小框里面的值
已解,在 optionFH.tooltip.position 里面就可以拿到