Skip to content

Commit 2715e5d

Browse files
committed
upd: chart.js to v3; vue-chartjs to v4
1 parent 85fe2e9 commit 2715e5d

File tree

4 files changed

+46
-86
lines changed

4 files changed

+46
-86
lines changed
Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,53 @@
1+
<template>
2+
<line-chart-element
3+
:chart-id="chartId"
4+
:chart-options="chartOptions"
5+
:chart-data="chartData"
6+
:width="width"
7+
:height="height"
8+
/>
9+
</template>
10+
111
<script>
2-
import { Line, mixins } from 'vue-chartjs'
12+
import { Line as LineChartElement } from 'vue-chartjs/legacy'
13+
import {
14+
Chart,
15+
LineElement,
16+
PointElement,
17+
LineController,
18+
LinearScale,
19+
CategoryScale,
20+
Tooltip
21+
} from 'chart.js'
22+
23+
Chart.register(LineElement, PointElement, LineController, LinearScale, CategoryScale, Tooltip)
324
425
export default {
526
name: 'LineChart',
6-
extends: Line,
7-
mixins: [mixins.reactiveProp],
27+
components: {
28+
LineChartElement
29+
},
830
props: {
9-
extraOptions: {
31+
chartId: {
32+
type: String,
33+
default: 'line-chart'
34+
},
35+
chartData: {
1036
type: Object,
11-
default: undefined
12-
}
13-
},
14-
data () {
15-
return {
16-
ctx: null
37+
default: null
38+
},
39+
chartOptions: {
40+
type: Object,
41+
default: null
42+
},
43+
width: {
44+
type: Number,
45+
default: 400
46+
},
47+
height: {
48+
type: Number,
49+
default: 150
1750
}
18-
},
19-
mounted () {
20-
this.$watch(
21-
'chartData',
22-
(newVal, oldVal) => {
23-
if (!oldVal) {
24-
this.renderChart(this.chartData, this.extraOptions)
25-
}
26-
},
27-
{ immediate: true }
28-
)
2951
}
3052
}
3153
</script>

src/components/Charts/chart.config.js

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,6 @@ export const chartColors = {
66
}
77
}
88

9-
export const chartOptionsMain = {
10-
maintainAspectRatio: false,
11-
legend: {
12-
display: false
13-
},
14-
responsive: true,
15-
tooltips: {
16-
backgroundColor: '#f5f5f5',
17-
titleFontColor: '#333',
18-
bodyFontColor: '#666',
19-
bodySpacing: 4,
20-
xPadding: 12,
21-
mode: 'nearest',
22-
intersect: 0,
23-
position: 'nearest'
24-
},
25-
scales: {
26-
yAxes: [
27-
{
28-
barPercentage: 1.6,
29-
gridLines: {
30-
drawBorder: false,
31-
color: 'rgba(29,140,248,0.0)',
32-
zeroLineColor: 'transparent'
33-
},
34-
ticks: {
35-
padding: 20,
36-
fontColor: '#9a9a9a'
37-
}
38-
}
39-
],
40-
41-
xAxes: [
42-
{
43-
barPercentage: 1.6,
44-
gridLines: {
45-
drawBorder: false,
46-
color: 'rgba(225,78,202,0.1)',
47-
zeroLineColor: 'transparent'
48-
},
49-
ticks: {
50-
padding: 20,
51-
fontColor: '#9a9a9a'
52-
}
53-
}
54-
]
55-
}
56-
}
57-
589
const randomChartData = n => {
5910
const data = []
6011

src/views/Home.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@
5959
class="chart-area"
6060
>
6161
<line-chart
62-
ref="bigChart"
63-
style="height: 100%;"
64-
chart-id="big-line-chart"
6562
:chart-data="chartData"
66-
:extra-options="chartOptions"
63+
:chart-options="{responsive: true}"
64+
:style="{height: '100%'}"
6765
/>
6866
</div>
6967
</card-component>
@@ -104,7 +102,6 @@ export default {
104102
data () {
105103
return {
106104
titleStack: ['Admin', 'Dashboard'],
107-
chartOptions: chartConfig.chartOptionsMain,
108105
chartData: null
109106
}
110107
},

vue.config.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
module.exports = {
22
publicPath: process.env.DEPLOY_ENV === 'GH_PAGES'
33
? '/admin-one-vue-bulma-dashboard/'
4-
: '/',
5-
6-
// Remove moment.js from chart.js
7-
// https://www.chartjs.org/docs/latest/getting-started/integration.html#bundlers-webpack-rollup-etc
8-
configureWebpack: config => {
9-
return {
10-
externals: {
11-
moment: 'moment'
12-
}
13-
}
14-
}
4+
: '/'
155
}

0 commit comments

Comments
 (0)