Extending chart in order to override draw function
See original GitHub issueI’d love extend the functionality of the bar chart by making it draw rounded bars instead of the standard ones. Here is a fiddle of how it can be realized out of vue.js context: http://jsfiddle.net/0dzp3jxw/
How can I possibly do that in vue-chartjs?
Currently I’m even struggling to find out how to create a custom chart and let the actual chart extend from that (intermediate heredity between native chart and used chart).
I created a chart like this:
# RoundedCorners.vue
<script>
import { Bar, mixins } from 'vue-chartjs'
export default {
extends: Bar,
mixins: [mixins.reactiveProp],
props: ['chartData', 'options'],
mounted () {
this.renderChart(this.chartData, this.options)
}
}
</script>
If I then create the actual chart and let it extend the newly created custom chart like this:
# FinancesChart
<script>
import { mixins } from 'vue-chartjs'
import { RoundedCorners} from './RoundedCorners'
export default {
extends: RoundedCorners,
mixins: [mixins.reactiveProp],
props: ['chartData', 'options'],
mounted () {
this.renderChart(this.chartData, this.options)
}
}
</script>
it says Failed to mount component: template or render function not defined.
and this.renderChart is not a function
.
So two questions: 1.) How would I create a three step heritage 2.) How could I then override the initialize or draw function like in the above code snippet?
Thanks a lot!
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
After having gained a little bit of understanding about the above mentioned (newer?) interface I was able to make it work. The animation is missing and there is a little clipping error but for everyone being interested in this it could be a good starting point.
https://github.com/chartjs/Chart.js/blob/master/src/controllers/controller.bar.js#L445 Having had a look at the implementation of the original draw function was quite helpful for me.
Well there are two ways.
Overwriting
You need to import the Chart.js object into your component. Then you can overwrite everything in there.
However with this approach you will overwrite the default Bar chart. So all your bar charts will have rounded corners.
This should work tho.
Custom Chart
As mentioned here #326 You can however also create your own custom chart. By using the
generateChart
helper.You create a new chart type
LineWithLine
orBarRounded
extend the default chart.http://vue-chartjs.org/#/home?id=custom-new-charts