Commit 785d0781 by shaojiawen

update: 图表

parent 23cfcce6
...@@ -127,7 +127,17 @@ export default { ...@@ -127,7 +127,17 @@ export default {
let resData = res.data; let resData = res.data;
that.loading = false; that.loading = false;
if (resData.code == 0) { if (resData.code == 0) {
that.overViewData = resData.result || {}; let result = resData.result || { addNumT: 0, addNum: 0, dateList: [] };
// result.dateList = [
// { bizDate: '2018/8/1', 新增人数: 0 },
// { bizDate: '2018/8/2', 新增人数: 1 },
// { bizDate: '2018/8/3', 新增人数: 1 },
// { bizDate: '2018/8/4', 新增人数: 1 }
// ];
result.dateList.map(function(date, index) {
date['新增人数'] = date.addNum;
});
that.overViewData = result;
return; return;
} }
errMsg.errorMsg(resData); errMsg.errorMsg(resData);
......
<template> <template>
<div> <div>
<div :id="id"></div> <div :id="id" class="chart--nodata" :style="!charData.length ? 'height:0;' : ''"></div>
<div v-if="!charData.length" class="chart--nodata"> <div v-if="!charData.length" class="chart--nodata">
<div> <div>
<img class="image-120" src="@/assets/no-data.svg" /> <img class="image-120" src="@/assets/no-data.svg" />
...@@ -8,18 +8,11 @@ ...@@ -8,18 +8,11 @@
</div> </div>
</div> </div>
</div> </div>
<!-- <div :id="id"></div> -->
<!-- <div v-if="!charData.length" class="chart--nodata">
<div>
<img class="image-120" src="@/assets/no-data.svg" />
<p class="font-14 color-606266 no-data-text">暂无数据</p>
</div>
</div> -->
</template> </template>
<script> <script>
// import G2 from '@antv/g2';
import * as G2 from '@antv/g2'; import * as G2 from '@antv/g2';
import filters from '@/filters/index';
export default { export default {
components: {}, components: {},
data() { data() {
...@@ -31,7 +24,7 @@ export default { ...@@ -31,7 +24,7 @@ export default {
charData: { charData: {
type: Array, type: Array,
default() { default() {
return []; //{ bizDate: '2018/8/1', 新增人数: 4623 } return [];
} }
}, },
id: String id: String
...@@ -62,18 +55,24 @@ export default { ...@@ -62,18 +55,24 @@ export default {
padding: [70, 60, 40, 70] padding: [70, 60, 40, 70]
}); });
//装载数据 //装载数据
let list = JSON.parse(JSON.stringify(this.charData));
// this.chart.data(this.charData); // 载入数据源 list.sort((a, b) => {
this.chart.data(this.charData, { return b.新增人数 - a.新增人数;
bizDate: { });
alias: '日期' //别名 let maxNum = list[0]['新增人数'];
}, // console.log(list);
addNum: { this.chart.data(this.charData); // 载入数据源
alias: '新增人数' this.chart.scale({
新增人数: {
// tickInterval: 1,
tickCount: maxNum > 2 ? 5 : maxNum + 1,
minTickInterval: 1,
nice: true,
min: 0
// type: 'linear'
} }
}); });
this.chart.axis('新增人数', {
this.chart.axis('addNum', {
grid: { grid: {
line: { line: {
type: 'line', type: 'line',
...@@ -93,42 +92,47 @@ export default { ...@@ -93,42 +92,47 @@ export default {
} }
} }
}); });
this.chart.tooltip({ // this.chart.tooltip({
showCrosshairs: true, // showCrosshairs: true,
shared: true, // shared: true,
itemTpl: `<div style="margin-bottom: 10px;list-style:none;"> // itemTpl: `<div style="margin-bottom: 10px;list-style:none;">
<span style="background-color:{color};" class="g2-tooltip-marker"></span> // <span style="background-color:{color};" class="g2-tooltip-marker"></span>
{name}: {value} // {name}: {value}
</div>` // </div>`
}); // });
// 图例 // 图例
this.chart.legend({ this.chart.legend({
custom: true, custom: true,
position: 'top-left', 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) { if (this.charData.length > 1) {
this.chart this.chart
.line() .line()
.position('bizDate*addNum') .position('bizDate*新增人数')
.color('#4B74E8') .color('#4B74E8');
.tooltip('addNum', addNum => { // .tooltip('addNum', addNum => {
return { // return {
name: '新增人数', // name: '新增人数',
value: addNum // value: addNum
}; // };
}); // });
} else { } 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 this.chart
.point() .point()
.position('bizDate*addNum') .position('bizDate*新增人数')
.color('#4B74E8') .color('#4B74E8');
.tooltip('addNum', addNum => { // .tooltip('addNum', addNum => {
return { // return {
name: '新增人数', // name: '新增人数',
value: addNum // value: addNum
}; // };
}); // });
} }
this.chart.removeInteraction('legend-filter'); // 自定义图例,移除默认的分类图例筛选交互 this.chart.removeInteraction('legend-filter'); // 自定义图例,移除默认的分类图例筛选交互
...@@ -140,7 +144,7 @@ export default { ...@@ -140,7 +144,7 @@ export default {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.chart--nodata { .chart--nodata {
height: 256px; height: 359px;
width: 100%; width: 100%;
display: flex; display: flex;
justify-content: center; justify-content: center;
......
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