Commit 3fed1eb6 by shaojiawen

update:图表

parent 841051c6
......@@ -94,7 +94,6 @@ export default {
} else {
// 近一年
setDate = endDate => {
console.log(endDate);
endDate.setFullYear(endDate.getFullYear() - 1);
endDate.setMonth(endDate.getMonth() + 1);
endDate.setDate(1);
......
......@@ -83,10 +83,11 @@ export default {
addNumT: 0,
addNum: 0,
dateList: [
// { bizDate: '2018/8/12', addNum: null },
// { bizDate: '2018-07', addNum: 0 }
// { bizDate: '2018/8/14', addNum: null }
// { bizDate: '2018/8/14', addNum: 289 }
// null,
// { bizDate: '2018-07-13', addNum: null },
// { bizDate: '2018-07-14', 新增人数: 11 },
// { bizDate: '2018-07-15', addNum: null }
// { bizDate: '2018-8-14', 新增人数: 289 }
// { bizDate: '2018/8/15', addNum: 289 },
// { bizDate: '2018/8/16', addNum: 29 },
// { bizDate: '2018/8/17', addNum: 289 },
......@@ -120,7 +121,11 @@ export default {
let resData = res.data;
that.loading = false;
if (resData.code == 0) {
that.overViewData = resData.result || {};
let result = resData.result || { addNumT: 0, addNum: 0, dateList: [] };
result.dateList.map(function(date) {
date['新增人数'] = date.addNum;
});
that.overViewData = result;
return;
}
errMsg.errorMsg(resData);
......
<template>
<div>
<div :id="id" class="chart--nodata"></div>
<div :id="id" class="chart--nodata" :style="!charData.length ? 'height:0;' : ''"></div>
<div v-if="!charData.length" class="chart--nodata">
<div>
<img class="image-120" src="@/assets/no-data.svg" />
......@@ -12,6 +12,7 @@
<script>
import * as G2 from '@antv/g2';
import filters from '@/filters/index';
export default {
components: {},
data() {
......@@ -48,7 +49,7 @@ export default {
methods: {
async drawChart() {
this.chart && this.chart.destroy();
if (!this.charData.length) return;
// if (!this.charData.length) return;
this.chart = new G2.Chart({
container: this.id,
autoFit: true,
......@@ -70,8 +71,7 @@ export default {
style: {
fill: '#E4E7ED',
lineDash: [3, 3]
},
alignTick: false
}
},
label: {
style: {
......@@ -79,7 +79,7 @@ export default {
}
}
});
this.chart.axis('addNum', {
this.chart.axis('新增人数', {
grid: {
line: {
type: 'line',
......@@ -99,42 +99,47 @@ export default {
}
}
});
this.chart.tooltip({
showCrosshairs: true,
shared: true,
itemTpl: `<div style="margin-bottom: 10px;list-style:none;">
<span style="background-color:{color};" class="g2-tooltip-marker"></span>
{name}: {value}
</div>`
});
// this.chart.tooltip({
// showCrosshairs: true,
// shared: true,
// itemTpl: `<div style="margin-bottom: 10px;list-style:none;">
// <span style="background-color:{color};" class="g2-tooltip-marker"></span>
// {name}: {value}
// </div>`
// });
// 图例
this.chart.legend({
custom: true,
position: 'top-left',
items: [{ name: '新增人数', value: 'addNum', marker: { symbol: 'line', style: { stroke: '#4B74E8', lineWidth: 12, lineHeight: 8 } } }]
items: [{ name: '新增人数', value: '新增人数', marker: { symbol: 'line', style: { stroke: '#4B74E8', lineWidth: 12, lineHeight: 8 } } }]
});
if (this.charData.length > 1) {
this.chart
.line()
.position('bizDate*addNum')
.color('#4B74E8')
.tooltip('addNum', addNum => {
return {
name: '新增人数',
value: addNum
};
});
} else {
.position('bizDate*新增人数')
.color('#4B74E8');
// .tooltip('addNum', addNum => {
// return {
// name: '新增人数',
// value: addNum
// };
// });
} else if (this.charData.length == 1) {
let time = new Date(this.charData[0].bizDate).getTime();
let start = { 新增人数: null, bizDate: filters.timeStampToYmd(time - 86400000) };
let end = { 新增人数: null, bizDate: filters.timeStampToYmd(time + 86400000) };
let list = [start, this.charData[0], end];
this.chart.data(list);
this.chart
.point()
.position('bizDate*addNum')
.color('#4B74E8')
.tooltip('addNum', addNum => {
return {
name: '新增人数',
value: addNum
};
});
.position('bizDate*新增人数')
.color('#4B74E8');
// .tooltip('addNum', addNum => {
// return {
// name: '新增人数',
// value: addNum
// };
// });
}
this.chart.removeInteraction('legend-filter'); // 自定义图例,移除默认的分类图例筛选交互
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment