Commit 30135bb4 by chenwq

折线图

1 parent 68889715
<template>
<div class="line-box">
<p v-if="title" class="title">{{ title }}</p>
<div id="line-chart" class="line-chart"></div>
<div id="echarts-line" class="echarts-line"></div>
<div class="rank-box">
<div>
<p :class="[ 'rank-title', rankFlag == 'first' ? 'rank-active' : '' ]" @click="handleRankChange('first')">前5{{ storeOrBrandTxt }}</p>
......@@ -13,9 +12,9 @@
<script>
import * as echarts from 'echarts'
import options from './lineOptions'
import getLineOptions from './lineOptions'
export default {
name: 'LineChart',
name: 'EchartLine',
props: {
// height: {
......@@ -26,10 +25,6 @@ export default {
type: String,
default: ''
},
title: {
type: String,
default: ''
},
storeOrBrandTxt: {
type: String,
default: '门店'
......@@ -38,15 +33,25 @@ export default {
data() {
return {
// first,last
rankFlag: 'first',
lineOptions: JSON.parse(JSON.stringify(options))
lineOptions: [],
xAxisLabel: {
monthList: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
},
echartsLine: '',
dataList: [1, 2, 3, 10, 5, 2, 7, 8, 9, 10, 11, 12],
moveAttr: {
speed: 900,
seriesIndex: 0,
dataIndex: -1
},
timer: null
// chartHeight: this.height
}
},
created() {
this.lineOptions = getLineOptions({ axisLabelColor: this.axisLabelColor })
},
mounted() {
......@@ -54,10 +59,50 @@ export default {
},
methods: {
dealxAxisLabel() {
this.lineOptions.xAxis.data = this.xAxisLabel.monthList
},
autoMove() {
clearTimeout(this.timer)
this.timer = setTimeout(() => {
this.moveAttr.dataIndex = this.moveAttr.dataIndex + 1
if (this.moveAttr.dataIndex === this.dataList.length) {
this.moveAttr.dataIndex = 0
}
this.moveAction()
this.autoMove()
}, this.moveAttr.speed)
},
chartBindEvent() {
this.echartsLine.on('click', () => {
// clearTimeout(this.timer)
console.log('???????')
})
},
moveAction(type) {
this.echartsLine.dispatchAction({
type: type || 'showTip',
seriesIndex: this.moveAttr.seriesIndex,
dataIndex: this.moveAttr.dataIndex
})
},
drawLine() {
var lineDom = document.getElementById('line-chart')
var lineChart = echarts.init(lineDom)
lineChart.setOption(this.lineOptions)
// var lineDom = document.getElementById('echarts-line')
// this.echartsLine = echarts.init(lineDom)
this.echartsLine = echarts.init(document.getElementById('echarts-line'))
this.dealxAxisLabel()
this.lineOptions.series[0].data = this.dataList
this.echartsLine.setOption(this.lineOptions)
console.log(this.echartsLine)
this.chartBindEvent()
// this.autoMove()
},
handleRankChange(value) {
......@@ -73,25 +118,25 @@ p {
}
.line-box {
color: #ffffff;
padding: 4px 8px;
// padding: 4px 8px;
font-size: 0.75em;
.title {
height: 17px;
color: #e8e8e8;
}
.line-chart {
height: calc(100% - 25px - 30px);
.echarts-line {
width: 100%;
height: calc(100% - 3.1vh - 4.6vh);
}
.rank-box {
box-sizing: border-box;
display: flex;
height: 30px;
height: 4.6vh;
padding: 0.48vh 0.87vh;
border-top: 1px solid #373739;
.rank-title {
box-sizing: border-box;
font-size: 0.6em;
background: #353535;
padding: 1px 5px;
height: 15px;
line-height: 15px;
height: 1.83vh;
line-height: 1.83vh;
opacity: 0.7;
cursor: pointer;
}
......
var lineOptions = {
visualMap: [
{
show: false,
type: 'continuous',
seriesIndex: 0,
min: 0,
max: 400
function getLineOptions(obj) {
// const { axisLabelColor } = obj
console.log(obj)
var lineOptions = {
tooltip: {
trigger: 'axis',
formatter: ''
},
{
show: false,
type: 'continuous',
seriesIndex: 1,
dimension: 0,
min: 0,
max: 0
}
],
title: [
{
left: 'center',
text: 'Gradient along the y axis'
grid: {
left: '3%',
right: '4%',
top: '10%',
bottom: '10%',
containLabel: true
},
{
top: '55%',
left: 'center',
text: 'Gradient along the x axis'
}
],
tooltip: {
trigger: 'axis'
},
xAxis: [
{
xAxis: {
type: 'category',
axisLabel: {
color: '#606266',
// color: axisLabelColor ? (value, index) => axisLabelColor(value, index) : '#606266',
fontSize: '0.8em'
},
data: []
},
{
data: [],
gridIndex: 1
}
],
yAxis: [
{},
{
gridIndex: 1
}
],
grid: [
{
bottom: '60%'
yAxis: {
type: 'value',
splitLine: {
lineStyle: {
color: '#606266'
}
}
},
{
top: '60%'
}
],
series: [
{
type: 'line',
showSymbol: false,
data: []
},
{
type: 'line',
showSymbol: false,
data: [],
xAxisIndex: 1,
yAxisIndex: 1
}
]
series: [
{
type: 'line',
itemStyle: {
color: '#F5AA01'
},
// 节点,平滑曲线
symbol: 'none',
smooth: true,
// 折线背景色
areaStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: 'rgba(254, 84, 0, 0.6)'
},
{
offset: 1,
color: 'rgba(254, 84, 0, 0.05)'
}
]
}
},
data: []
}
]
}
return lineOptions
}
export default lineOptions
export default getLineOptions
......@@ -8,11 +8,18 @@
<template>
<div>
<div class="title">售后档案客户</div>
<echart-line :height="height"></echart-line>
</div>
</template>
<script>
export default {
name: 'File'
name: 'File',
props: {
height: {
type: String,
default: '19.8vh'
}
}
}
</script>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!