refactor(charts): add CustomTooltips, add chartId prop
This commit is contained in:
@@ -1,20 +1,39 @@
|
||||
<script>
|
||||
import { Bar } from 'vue-chartjs'
|
||||
import { CustomTooltips } from '@coreui/coreui-plugin-chartjs-custom-tooltips'
|
||||
|
||||
export default {
|
||||
extends: Bar,
|
||||
mounted () {
|
||||
// Overwriting base render method with actual data.
|
||||
this.renderChart({
|
||||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||
datasets: [
|
||||
{
|
||||
label: 'GitHub Commits',
|
||||
backgroundColor: '#f87979',
|
||||
data: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
|
||||
this.renderChart(
|
||||
{
|
||||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||
datasets: [
|
||||
{
|
||||
label: 'GitHub Commits',
|
||||
backgroundColor: '#f87979',
|
||||
data: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
responsive: true,
|
||||
maintainAspectRatio: true,
|
||||
tooltips: {
|
||||
enabled: false,
|
||||
custom: CustomTooltips,
|
||||
intersect: true,
|
||||
mode: 'index',
|
||||
position: 'nearest',
|
||||
callbacks: {
|
||||
labelColor: function (tooltipItem, chart) {
|
||||
return { backgroundColor: chart.data.datasets[tooltipItem.datasetIndex].backgroundColor }
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -17,7 +17,7 @@ export default {
|
||||
data: [40, 20, 80, 10]
|
||||
}
|
||||
]
|
||||
}, {responsive: true, maintainAspectRatio: false})
|
||||
}, {responsive: true, maintainAspectRatio: true})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,19 +1,48 @@
|
||||
<script>
|
||||
import { Line } from 'vue-chartjs'
|
||||
import { CustomTooltips } from '@coreui/coreui-plugin-chartjs-custom-tooltips'
|
||||
import { hexToRgba } from '@coreui/coreui/dist/js/coreui-utilities'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
hexToRgba,
|
||||
CustomTooltips
|
||||
},
|
||||
extends: Line,
|
||||
mounted () {
|
||||
this.renderChart({
|
||||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
||||
datasets: [
|
||||
{
|
||||
label: 'Data One',
|
||||
backgroundColor: '#f87979',
|
||||
data: [40, 39, 10, 40, 39, 80, 40]
|
||||
this.renderChart(
|
||||
{
|
||||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
||||
datasets: [
|
||||
{
|
||||
label: 'Data One',
|
||||
backgroundColor: hexToRgba('#E46651', 90),
|
||||
data: [30, 39, 10, 50, 30, 70, 35]
|
||||
},
|
||||
{
|
||||
label: 'Data Two',
|
||||
backgroundColor: hexToRgba('#00D8FF', 90),
|
||||
data: [39, 80, 40, 35, 40, 20, 45]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
responsive: true,
|
||||
maintainAspectRatio: true,
|
||||
tooltips: {
|
||||
enabled: false,
|
||||
custom: CustomTooltips,
|
||||
intersect: true,
|
||||
mode: 'index',
|
||||
position: 'nearest',
|
||||
callbacks: {
|
||||
labelColor: function (tooltipItem, chart) {
|
||||
return { backgroundColor: chart.data.datasets[tooltipItem.datasetIndex].backgroundColor }
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}, {responsive: true, maintainAspectRatio: false})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -17,7 +17,7 @@ export default {
|
||||
data: [40, 20, 80, 10]
|
||||
}
|
||||
]
|
||||
}, {responsive: true, maintainAspectRatio: false})
|
||||
}, {responsive: true, maintainAspectRatio: true})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script>
|
||||
import { PolarArea } from 'vue-chartjs'
|
||||
import { CustomTooltips } from '@coreui/coreui-plugin-chartjs-custom-tooltips'
|
||||
|
||||
export default {
|
||||
extends: PolarArea,
|
||||
@@ -26,7 +27,22 @@ export default {
|
||||
data: [28, 48, 40, 19, 96, 27, 100]
|
||||
}
|
||||
]
|
||||
}, {responsive: true, maintainAspectRatio: false})
|
||||
}, {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
tooltips: {
|
||||
enabled: false,
|
||||
custom: CustomTooltips,
|
||||
intersect: true,
|
||||
mode: 'index',
|
||||
position: 'nearest',
|
||||
callbacks: {
|
||||
labelColor: function (tooltipItem, chart) {
|
||||
return { backgroundColor: chart.data.datasets[tooltipItem.datasetIndex].backgroundColor }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script>
|
||||
import { Radar } from 'vue-chartjs'
|
||||
import { CustomTooltips } from '@coreui/coreui-plugin-chartjs-custom-tooltips'
|
||||
|
||||
export default {
|
||||
extends: Radar,
|
||||
@@ -8,7 +9,7 @@ export default {
|
||||
labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
|
||||
datasets: [
|
||||
{
|
||||
label: 'My First dataset',
|
||||
label: '2017',
|
||||
backgroundColor: 'rgba(179,181,198,0.2)',
|
||||
borderColor: 'rgba(179,181,198,1)',
|
||||
pointBackgroundColor: 'rgba(179,181,198,1)',
|
||||
@@ -18,7 +19,7 @@ export default {
|
||||
data: [65, 59, 90, 81, 56, 55, 40]
|
||||
},
|
||||
{
|
||||
label: 'My Second dataset',
|
||||
label: '2018',
|
||||
backgroundColor: 'rgba(255,99,132,0.2)',
|
||||
borderColor: 'rgba(255,99,132,1)',
|
||||
pointBackgroundColor: 'rgba(255,99,132,1)',
|
||||
@@ -28,7 +29,22 @@ export default {
|
||||
data: [28, 48, 40, 19, 96, 27, 100]
|
||||
}
|
||||
]
|
||||
}, {responsive: true, maintainAspectRatio: false})
|
||||
}, {
|
||||
responsive: true,
|
||||
maintainAspectRatio: true,
|
||||
tooltips: {
|
||||
enabled: false,
|
||||
custom: CustomTooltips,
|
||||
intersect: true,
|
||||
mode: 'index',
|
||||
position: 'nearest',
|
||||
callbacks: {
|
||||
labelColor: function (tooltipItem, chart) {
|
||||
return { backgroundColor: chart.data.datasets[tooltipItem.datasetIndex].borderColor }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user