<!-- * @Description: 交通指数趋势 * @Author: 王晓颖 * @Date: 2020-10-13 14:31:45 --> <template> <single-layout title="日交通指数趋势"> <div style="width: 100%;height:100%;padding:0rem 0.1rem"> <gradient-line-chart :id="options.id" :unit="options.unit" :height="options.height" :legend="options.xAxisData" :xAxisData="options.xAxisData" :seriesData="options.seriesData" /> </div> </single-layout> </template> <script> import GradientLineChart from '@/components/lineChart/gradientLineChart' import {fetchCaseByDay} from '@/api/smartTraffic' import SingleLayout from '@/components/layout/singleLayout' export default { name: 'trafficIndexLine', components: {SingleLayout, GradientLineChart}, data () { return { options: { id: 'traffic_index_count_line', height: '100%', width: '100%', unit: '个', xAxisData: ['周一','周二','周三','周四','周五','周六', '周日'], seriesData: [ // {name: '拥堵指数', data: [0, 0, 0, 0, 0, 2, 4], color: '255,45,85'}, // {name: '违章事故指数', data: [0, 0, 0, 0, 0, 1, 3], color: '255,204,0'}, // {name: '交通流量', data: [1, 1, 1, 1, 1, 3, 5], color: '0,144,255'} ] } } }, created () { // this.getData() const mockData = this.$globalJsons.globalCity this.options.xAxisData = mockData.traffic.safe.line.xData this.options.seriesData = mockData.traffic.safe.line.yData }, methods: { getData () { fetchCaseByDay().then(response => { if (response.code === 200) { const data = response.data this.options.xAxisData = data.map(item => { return item.name }) const value = data.map(item => { return item.value }) this.options.seriesData = [ {name: '事故数量', data: value, color: '255,45,85'} ] } }) } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> </style>