Commit 374b76ad by 前端
2 parents cc5fec92 55920f4b
...@@ -28,7 +28,7 @@ Component({ ...@@ -28,7 +28,7 @@ Component({
text: '年', text: '年',
type: 3 type: 3
}, ], }, ],
timePeriod: 2 timePeriod: 1
}, },
...@@ -50,7 +50,6 @@ Component({ ...@@ -50,7 +50,6 @@ Component({
this.triggerEvent('selectEvent') this.triggerEvent('selectEvent')
}, },
selectTime() { selectTime() {
console.log(122)
this.triggerEvent('selectTime') this.triggerEvent('selectTime')
}, },
......
import * as echarts from '../../../../ec-canvas/echarts'; import * as echarts from '../../../outDetail/ec-canvas/echarts';
Component({ Component({
/** /**
...@@ -24,16 +24,8 @@ Component({ ...@@ -24,16 +24,8 @@ Component({
}, },
observers: { observers: {
'chartData': function (data) { 'chartData': function (data) {
if (data.length == 0) { console.log(data, '9999999999')
this.setData({ this.initData(data)
chartShow: true,
ec: {
onInit: this.onInitChart() //这里就是在js中用到的方法名
}
})
} else {
// this.data.chart.changeData(data)
}
}, },
...@@ -43,7 +35,7 @@ Component({ ...@@ -43,7 +35,7 @@ Component({
*/ */
data: { data: {
ec: { ec: {
onInit: null lazyLoad: true
} }
}, },
...@@ -51,112 +43,116 @@ Component({ ...@@ -51,112 +43,116 @@ Component({
* 组件的方法列表 * 组件的方法列表
*/ */
methods: { methods: {
onInitChart() { onInitChart(xData, yData) {
return (canvas, width, height, dpr) => { this.ecComponent && this.ecComponent.init((canvas, width, height, dpr) => {
const chart = echarts.init(canvas, null, { const chart = echarts.init(canvas, null, {
width: width, width: width,
height: height, height: height,
devicePixelRatio: dpr, // new devicePixelRatio: dpr,
padding:[10, 20,10,20]
}); });
canvas.setChart(chart); this.setOption(chart, xData, yData);
return chart;
})
var option = { },
grid: { setOption(chart, xData, yData) {
left: 8, var option = {
right: 10, grid: {
top: 50, left: 8,
bottom: 0, right: 10,
containLabel: true top: 50,
}, bottom: 0,
tooltip: { containLabel: true
trigger: 'axis', },
triggerOn: "mousemove", tooltip: {
axisPointer: { trigger: 'axis',
lineStyle: { triggerOn: "mousemove",
type: 'solid' axisPointer: {
} lineStyle: {
}, type: 'solid'
padding: [2, 10],
borderWidth: 2,
borderColor: this.data.color,
borderRadius: 10,
textStyle: {
color: this.data.color,
fontSize: 10
},
// position: function(pt) {
// console.log(pt)
// return [pt[0], pt[1]+20];
// },
formatter: function (item) {
console.log(item)
return `${item[0].value}` + '人'
} }
}, },
xAxis: { padding: [2, 10],
type: 'category', borderWidth: 2,
axisLabel: { borderColor: this.data.color,
fontSize: 11, borderRadius: 10,
color: '#A6A6A6' textStyle: {
}, color: this.data.color,
axisLine: { fontSize: 10
show: false //坐标轴线线 },
}, // position: function(pt) {
axisTick: { // console.log(pt)
show: false //坐标轴刻度 // return [pt[0], pt[1]+20];
}, // },
data: ['Mon', 'Tue', 'Wed', 'Thu'] formatter: function (item) {
console.log(item)
return `${item[0].value}` + '人'
}
},
xAxis: {
type: 'category',
axisLabel: {
fontSize: 11,
color: '#A6A6A6'
},
axisLine: {
show: false //坐标轴线线
},
axisTick: {
show: false //坐标轴刻度
}, },
yAxis: { data: xData
x: 'center', },
type: 'value', yAxis: {
axisLabel: { x: 'center',
fontSize: 11, type: 'value',
color: '#A6A6A6' axisLabel: {
}, fontSize: 11,
axisLine: { color: '#A6A6A6'
show: false //坐标轴线线 },
}, axisLine: {
axisTick: { show: false //坐标轴线线
show: false //坐标轴刻度 },
}, axisTick: {
splitLine: { show: false //坐标轴刻度
lineStyle: { },
type: 'dashed' splitLine: {
} lineStyle: {
type: 'dashed'
} }
}
},
series: [{
data: yData,
type: 'bar',
color: this.data.color,
itemStyle: {
borderRadius: [50, 50, 0, 0],
padding: [50, 50, 0, 0]
}, },
series: [{ barWidth: 24
data: [820, 932, 901, 934], }]
type: 'bar', };
color: this.data.color, chart.setOption(option)
itemStyle: {
borderRadius: [50, 50, 0, 0],
padding:[50, 50, 0, 0]
},
barWidth: 24
}]
};
chart.setOption(option);
return chart;
}
}, },
//初始化数据 //初始化数据
initData() { initData(data) {
let { const xData = [],
chartData, yData = [];
keys, const [x, y] = this.data.keys
viewData data.forEach(item => {
} = this xData.push(item[x])
chartData.forEach(item => { yData.push(item[y])
viewData.push({
name: item[keys[0]],
value: item[keys[1]]
})
}) })
this.setData({
xData,
yData
})
this.onInitChart(xData, yData)
}, },
},
ready() {
// 获取组件
this.ecComponent = this.selectComponent('#mychart-dom-bar');
} }
}) })
\ No newline at end of file \ No newline at end of file
{ {
"component": true, "component": true,
"usingComponents": { "usingComponents": {
"ec-canvas": "../../../../ec-canvas/ec-canvas" "ec-canvas": "../../../outDetail/ec-canvas/ec-canvas"
} }
} }
import * as echarts from '../../../../ec-canvas/echarts'; import * as echarts from '../../../outDetail/ec-canvas/echarts';
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
...@@ -24,18 +24,6 @@ Component({ ...@@ -24,18 +24,6 @@ Component({
observers: { observers: {
'chartData': function (data) { 'chartData': function (data) {
this.initData(data) this.initData(data)
if (data.length == 0) {
this.setData({
chartShow: true,
ec: {
onInit: this.onInitChart()
}
})
} else {
// this.data.chart.changeData(data)
}
}, },
}, },
/** /**
...@@ -43,10 +31,8 @@ Component({ ...@@ -43,10 +31,8 @@ Component({
*/ */
data: { data: {
ec: { ec: {
onInit: null lazyLoad: true
}, }
xData:[],
yData:[]
}, },
...@@ -54,114 +40,119 @@ Component({ ...@@ -54,114 +40,119 @@ Component({
* 组件的方法列表 * 组件的方法列表
*/ */
methods: { methods: {
onInitChart() { onInitChart(xData,yData) {
return (canvas, width, height, dpr) => { this.ecComponent&&this.ecComponent.init((canvas, width, height, dpr) => {
console.log(width, height, )
const chart = echarts.init(canvas, null, { const chart = echarts.init(canvas, null, {
width: width, width: width,
height: height, height: height,
devicePixelRatio: dpr // new devicePixelRatio: dpr // new
}); });
canvas.setChart(chart); this.setOption(chart,xData,yData);
return chart;
})
},
setOption(chart,xData,yData) {
var option = {
grid: {
left: 8,
right: 30,
top: 50,
bottom: 0,
containLabel: true
},
tooltip: {
trigger: 'axis',
triggerOn: "mousemove",
axisPointer: {
lineStyle: {
type: 'solid'
}
},
padding: [2, 10],
borderWidth: 2,
borderColor: '#6ED0BE',
borderRadius: 10,
textStyle: {
color: '#6ED0BE',
fontSize: 10
},
// position: function(pt) {
// console.log(pt)
// return [pt[0], pt[1]+20];
// },
formatter: function (item) {
console.log(item)
return `${item[0].value}` + '人'
}
},
xAxis: {
type: 'category',
boundaryGap: false,
// min:1,
// max: 5,
var option = { axisLabel: {
grid: { fontSize: 11,
left: 8, color: '#A6A6A6'
right: 10,
top: 50,
bottom: 0,
containLabel: true
}, },
tooltip: { axisLine: {
trigger: 'axis', show: false //坐标轴线线
triggerOn: "mousemove",
axisPointer: {
lineStyle: {
type: 'solid'
}
},
padding: [2, 10],
borderWidth: 2,
borderColor: '#6ED0BE',
borderRadius: 10,
textStyle: {
color: '#6ED0BE',
fontSize: 10
},
// position: function(pt) {
// console.log(pt)
// return [pt[0], pt[1]+20];
// },
formatter: function (item) {
console.log(item)
return `${item[0].value}` + '人'
}
}, },
xAxis: { axisTick: {
type: 'category', show: false //坐标轴刻度
boundaryGap: false,
axisLabel: {
fontSize: 11,
color: '#A6A6A6'
},
axisLine: {
show: false //坐标轴线线
},
axisTick: {
show: false //坐标轴刻度
},
data:this.data.xData
}, },
yAxis: { data: xData
x: 'center', },
type: 'value', yAxis: {
axisLabel: { x: 'center',
fontSize: 11, type: 'value',
color: '#A6A6A6' axisLabel: {
}, fontSize: 11,
axisLine: { color: '#A6A6A6'
show: false //坐标轴线线
},
axisTick: {
show: false //坐标轴刻度
},
splitLine: {
lineStyle: {
type: 'dashed'
}
}
}, },
dataZoom: { axisLine: {
start: 10, show: false //坐标轴线线
type: "inside"
}, },
series: [{ axisTick: {
data: this.data.yData, show: false //坐标轴刻度
type: 'line', },
smooth: true, splitLine: {
color: this.data.color lineStyle: {
}] type: 'dashed'
}; }
}
chart.setOption(option); },
return chart; dataZoom: {
type: "inside",
maxSpan: 10
},
series: [{
data: yData,
type: 'line',
smooth: true,
color: this.data.color
}]
} }
chart.setOption(option)
}, },
//初始化数据 //初始化数据
initData(data) { initData(data) {
let { const xData = [],
xData, yData = [];
yData const [x, y] = this.data.keys
} = this.data
data.forEach(item => { data.forEach(item => {
xData.push(item.abscissaValue) xData.push(item[x])
yData.push(item.ordinateValue) yData.push(item[y])
}) })
this.setData({ this.setData({
xData, xData,
yData yData
}) })
this.onInitChart(xData, yData)
}, },
},
ready() {
// 获取组件
this.ecComponent = this.selectComponent('#mychart-dom-line');
} }
}) })
\ No newline at end of file \ No newline at end of file
{ {
"component": true, "component": true,
"usingComponents": { "usingComponents": {
"ec-canvas": "../../../../ec-canvas/ec-canvas" "ec-canvas": "../../../outDetail/ec-canvas/ec-canvas"
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!