Skip to content

Commit

Permalink
feat: add chart-bar to analysis page
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwa committed Sep 24, 2018
1 parent a9c200a commit 3af3224
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion mock/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const visitors = {

export const payments = {
total: 6560,
chart: [],
chart: visitorData, // simulate fake datasets
rate: 0.6
}

Expand Down
6 changes: 3 additions & 3 deletions mock/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import dayjs from 'dayjs'

const visitorData = []
const beginDay = new Date().getTime()
const fakeDailyVisitor = [7, 5, 4, 2, 4, 7, 5, 6, 5, 9, 6, 3, 1, 5, 3, 6, 5]
const fakeY = [7, 5, 4, 2, 4, 7, 5, 6, 5, 9, 6, 3, 1, 5, 3, 6, 5]

for (let i = 0; i < fakeDailyVisitor.length; i++) {
for (let i = 0; i < fakeY.length; i++) {
visitorData.push({
date: dayjs(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
visitors: fakeDailyVisitor[i]
visitors: fakeY[i]
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/ChartLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default {
// 需要在极其精确的 hover 状态下才能触发 dot 样式
elements: {
point: {
radius: 0,
radius: 1,
hoverRadius: 4
}
},
Expand Down
27 changes: 21 additions & 6 deletions src/view/Analysis/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
responsive: true,
maintainAspectRatio: false // 保持长宽比
}"
:labels="visitorData.labels"
:datasets="visitorData.datasets"
:labels="visitorsData.labels"
:datasets="visitorsData.datasets"
></chart-line>
</main>
</chart-card>
Expand All @@ -44,7 +44,17 @@
:footerTitle="'转化率'"
:footerDetail="percentValue(payments.rate)"
>
<main class="placeholder__layout">card body</main>
<main class="placeholder__layout">
<chart-bar
class="chart__layout"
:options="{
responsive: true,
maintainAspectRatio: false
}"
:labels="paymentsData.labels"
:datasets="paymentsData.datasets"
></chart-bar>
</main>
</chart-card>
</el-col>

Expand Down Expand Up @@ -77,10 +87,11 @@
<script>
import ChartCard from 'COMPONENTS/ChartCard'
import ChartLine from 'COMPONENTS/ChartLine'
import ChartBar from 'COMPONENTS/ChartBar'
import MiniProgress from 'COMPONENTS/MiniProgress'
import Trend from 'COMPONENTS/Trend'
import { mapState, mapActions } from 'vuex'
import { formatVisitorData } from './utils'
import { formatData } from './utils'
import {
formatPrice,
decimalNumber
Expand All @@ -91,8 +102,11 @@ import { sales, visitors, payments, operations } from 'MOCK/analysis'
export default {
computed: {
visitorData () {
return formatVisitorData(this.visitors.chart)
visitorsData () {
return formatData(this.visitors.chart)
},
paymentsData () {
return formatData(this.payments.chart)
},
...mapState([
'sales',
Expand Down Expand Up @@ -137,6 +151,7 @@ export default {
Trend,
ChartCard,
ChartLine,
ChartBar,
MiniProgress
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/view/Analysis/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function formatVisitorData (visitorsData) {
export function formatData (set) {
const labels = []
const datasets = []
for (const daily of visitorsData) {
for (const daily of set) {
labels.push(daily.date)
datasets.push(daily.visitors)
}
Expand Down

0 comments on commit 3af3224

Please sign in to comment.