源碼
function getValues(){
var type = "TMP";
var apoint = arguments[] ? arguments[] : ;// 設定參數point的預設值為20
var pdata = {
"point" : apoint
};
$.ajax({
type : "post",
async : true, //異步請求(同步請求将會鎖住浏覽器,使用者其他操作必須等待請求完成才可以執行)
url : "接口" + type, //請求發送處
data : pdata,
dataType : "json", //傳回資料形式為json
success : function(result) {
//請求成功時執行該函數内容,result即為伺服器傳回的json對象
if (result) {
var pointsarr = result.points;
showTrend(pointsarr);
}
},
error:function(errorMsg) {
//請求失敗時執行該函數
alert("圖表請求資料失敗!");
}
})
}
function showTrend(pointsarr){
var symbolSize = ;
var categories = ['1h','2h','3h','4h','5h','6h','7h','8h','9h','10h','11h','12h','13h','14h','15h','16h','17h','18h','19h','20h','21h','22h','23h','24h'];//類别數組(x軸值)
var data = [[, pointsarr[].value], [, pointsarr[].value], [, pointsarr[].value],
[, pointsarr[].value], [, pointsarr[].value], [, pointsarr[].value],
[, pointsarr[].value], [, pointsarr[].value], [, pointsarr[].value],
[, pointsarr[].value], [, pointsarr[].value]];//y軸數值
var myChart = echarts.init(document.getElementById('trendRight'));
myChart.setOption({
tooltip: {
triggerOn: 'none',
formatter: function (params) {
return 'X: ' + params.data[].toFixed() + '<br>Y: ' + params.data[].toFixed();
}
},
xAxis: [{
type: 'category',
splitNumber:,//劃分為24個間隔
boundaryGap: false,
data: categories,
axisLine:{//x軸的橫坐标邊框線
show: false
},axisTick:{
show: false,
},axisLabel:{
show:true,
textStyle:{
fontSize:"8px",
color:"black",
align:"center"
},formatter:function(e){
return e;
}
},
splitLine: {
show: true,
lineStyle:{
color:"#e4e4e4",
type:"solid",
opacity:"0.75"
}
}
}
],
yAxis: [{
min: ,
max: ,
type: 'value',
splitNumber: ,
axisLine:{
show: true,
lineStyle:{
color:"#e4e4e4"
}
},axisTick:{
show: false,
},axisLabel:{
show:true,
textStyle:{
fontSize:"8px",
color:"black"
}
},
splitLine: {
show: true,
lineStyle:{
color:"#e4e4e4",
type:"solid",
opacity:"0.75"
}
}
}
],
lineStyle: {
normal: {
type: 'solid',
color:"#28a5fc",
opacity :"0.75"
}
},
series: [
{
id: 'a',
type: 'line',
smooth: true,
symbolSize: symbolSize,
lineStyle:{//折線的顔色
normal: {
color:"#1ba0fc",
width:,
type:'solid',
opacity:"0.75"
//shadowBlur:80
},
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(, , , , [{
offset: ,
color: 'rgba(40, 182, 252, 0.85)'
}, {
offset: ,
color: 'rgba(28, 159, 255, 0.2)'
}])
}
},itemStyle:{
normal:{
color:"#96BBCD",
barBorderColor:"#FAFCFD",
}
},
data: data
}
],
grid:{
left:,
top:,
bottom:,
right:,
show:true,
borderColor:"#e4e4e4",//網格邊框線
shadowColor:"#e4e4e4",
borderWidth:"0.2",
containLabel: false
}
});
myChart.setOption({
graphic: echarts.util.map(data, function (item, dataIndex) {
return {
type: 'circle',
position: myChart.convertToPixel('grid', item),
shape: {
r: symbolSize / ,
},
invisible: true,
draggable: true,
ondrag: echarts.util.curry(onPointDragging, dataIndex),
onmousemove: echarts.util.curry(showTooltip, dataIndex),
onmouseout: echarts.util.curry(hideTooltip, dataIndex),
z:
};
})
});
window.addEventListener('resize', function () {
myChart.setOption({
graphic: echarts.util.map(data, function (item, dataIndex) {
return {
position: myChart.convertToPixel('grid', item)
};
})
});
});
function showTooltip(dataIndex) {//顯示滑鼠移入圓圈點的數值
myChart.dispatchAction({
type: 'showTip',
seriesIndex: ,
dataIndex: dataIndex
});
}
function hideTooltip(dataIndex) {//隐藏
myChart.dispatchAction({
type: 'hideTip'
});
}
function onPointDragging(dataIndex, dx, dy) {
data[dataIndex] = myChart.convertFromPixel('grid', this.position);
myChart.setOption({
series: [{
id: 'a',
data: data
}]
});
var dataValues = data;
localStorage.setItem("data", JSON.stringify(dataValues));
}
}