diff --git a/src/components/charts/G2/components/Line/base.vue b/src/components/charts/G2/components/Line/base.vue index b6d2c22d..653f6650 100644 --- a/src/components/charts/G2/components/Line/base.vue +++ b/src/components/charts/G2/components/Line/base.vue @@ -16,10 +16,10 @@ export default { this.creatChart() // 本组件的特殊设置 this.chart.source(this.data) - this.chart.scale('value', { + this.chart.scale('y', { min: 0 }) - this.chart.scale('year', { + this.chart.scale('x', { range: [0, 1] }) this.chart.tooltip({ @@ -27,8 +27,8 @@ export default { type: 'line' } }) - this.chart.line().position('year*value') - this.chart.point().position('year*value').size(4).shape('circle').style({ + this.chart.line().position('x*y') + this.chart.point().position('x*y').size(4).shape('circle').style({ stroke: '#fff', lineWidth: 1 }) diff --git a/src/components/charts/G2/components/Line/step.vue b/src/components/charts/G2/components/Line/step.vue index cc390055..708e2754 100644 --- a/src/components/charts/G2/components/Line/step.vue +++ b/src/components/charts/G2/components/Line/step.vue @@ -16,11 +16,11 @@ export default { this.creatChart() // 本组件的特殊设置 this.chart.source(this.data, { - month: { + x: { range: [0, 1] } }) - this.chart.line().position('month*value').shape('hv') + this.chart.line().position('x*y').shape('hv') // 渲染图表 this.chart.render() }, diff --git a/src/mock/chart/G2Line.js b/src/mock/chart/G2Line.js index dd186182..ef3a50f4 100644 --- a/src/mock/chart/G2Line.js +++ b/src/mock/chart/G2Line.js @@ -16,17 +16,20 @@ Mock.mock('/api/chart/G2Line', 'post', ({body, type, url}) => { const _body = JSON.parse(body) switch (_body.type) { case 'base': { - let lastValue = 0 + let last = 0 const year = ['1991', '1992', '1993', '1994', '1995', '1996', '1997', '1998', '1999'] const data = year.map(e => ({ year: e, value: 0 })).map(e => { - e.value = lastValue + r() - lastValue = e.value + e.value = last + r() + last = e.value return e - }) - lastValue = 0 + }).map(e => ({ + x: e.year, + y: e.value + })) + last = 0 return returnMaker(data) } case 'step': { @@ -37,7 +40,10 @@ Mock.mock('/api/chart/G2Line', 'post', ({body, type, url}) => { })).map(e => { e.value = r() return e - }) + }).map(e => ({ + x: e.month, + y: e.value + })) return returnMaker(data) } default: