Browse Source

折线图

shibei_master
jiangyy 4 years ago
parent
commit
187cd51b2f
  1. 5
      src/views/modules/visual/communityGovern/cpt/issue-info.vue
  2. 24
      src/views/modules/visual/cpts/line-chart.vue

5
src/views/modules/visual/communityGovern/cpt/issue-info.vue

@ -80,7 +80,8 @@
</div> </div>
</div> </div>
<line-chart :list="issueChartData" /> <line-chart ref="lineChart"
:list="null" />
</div> </div>
</div> </div>
</cpt-card> </cpt-card>
@ -215,6 +216,8 @@ export default {
); );
}); });
this.issueChartData = chartData; this.issueChartData = chartData;
this.$refs.lineChart.setList(this.issueChartData)
} else { } else {
this.$message.error(msg); this.$message.error(msg);
} }

24
src/views/modules/visual/cpts/line-chart.vue

@ -1,6 +1,8 @@
<template> <template>
<div class="m-chart"> <div class="m-chart">
<canvas id="myChart" :width="width" :height="height" /> <canvas id="myChart"
:width="width"
:height="height" />
</div> </div>
</template> </template>
@ -26,7 +28,7 @@ const addTextShape = () => {
const group = canvas.addGroup(); const group = canvas.addGroup();
const shapes = {}; const shapes = {};
function addFn(list) { function addFn (list) {
const listLength = list.length; const listLength = list.length;
list.forEach(function (obj, index) { list.forEach(function (obj, index) {
// //
@ -130,7 +132,7 @@ const iniChart = function (config, srcData) {
items: [ items: [
{ {
name: "支持", name: "支持",
marker(x, y, r, ctx) { marker (x, y, r, ctx) {
ctx.lineWidth = 10; ctx.lineWidth = 10;
ctx.strokeStyle = supColor; ctx.strokeStyle = supColor;
ctx.moveTo(x - r - 15, y); ctx.moveTo(x - r - 15, y);
@ -141,7 +143,7 @@ const iniChart = function (config, srcData) {
}, },
{ {
name: "反对", name: "反对",
marker(x, y, r, ctx) { marker (x, y, r, ctx) {
ctx.lineWidth = 10; ctx.lineWidth = 10;
ctx.strokeStyle = oppColor; ctx.strokeStyle = oppColor;
ctx.moveTo(x - r - 15, y); ctx.moveTo(x - r - 15, y);
@ -198,24 +200,32 @@ export default {
default: 260, default: 260,
}, },
}, },
data() { data () {
return { return {
iniLoading: false, iniLoading: false,
}; };
}, },
watch: { watch: {
list(data) { list (data) {
chart.changeData(data); chart.changeData(data);
srcData = data; srcData = data;
addTextShape(); addTextShape();
}, },
}, },
async created() { async created () {
await nextTick(200); await nextTick(200);
iniChart(this.config, this.list); iniChart(this.config, this.list);
await nextTick(200); await nextTick(200);
this.iniLoading = true; this.iniLoading = true;
}, },
methods: {
setList (data) {
chart.changeData(data);
srcData = data;
addTextShape();
},
}
}; };
</script> </script>

Loading…
Cancel
Save