question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vue-chartjs V4 with mixed chart type using Typescript

See original GitHub issue

Would you like to work on this feature?

  • Check this if you would like to implement a PR, we are more than happy to help you go through the process.

What problem are you trying to solve?

Trying to use a mixed chart but can’t find a way to implement. Have looked at;

  • 123 - But I get Bar.extend is not a function
  • 29 - But I get Chart.Bar.extend is not a function

I’m not able to see a way to do this with V4 and TS.

Describe the solution you’d like

Ability to create new custom mixed chart.

Describe alternatives you’ve considered

No response

Documentation, Adoption, Migration Strategy

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
mcelligottnickcommented, Nov 24, 2022

@ArturoTorresMartinez this is very stripped down and not exactly working, but this should give you an idea. Note the main thing you have to populate is the datasets array.

<template>
	<Bar
		v-if="activities.length > 0"
		:chart-data="chartData.data"
		:chart-options="chartData.options"
		:height="200"
	/>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { Bar } from 'vue-chartjs';
import { Chart, BarElement, LineController } from 'chart.js';

Chart.register(BarElement, LineController);

export default defineComponent({
	components: { Bar },
	computed: {
		chartData() {
			// can't get any correcty typings working here, I think because
			// we are using a mixed chart type
			const d = {
				data: {
					datasets: [],
				},
				options: {
					scales: {
						monetary: {
							position: 'right',
							ticks: {
								beginAtZero: true,
							},
							title: {
								display: true,
								text: 'Monetary',
							},
						},
						acc: {
							position: 'left',
							ticks: {
								beginAtZero: true,
							},
							grid: {
								// only want the grid lines for one axis to show up
								drawOnChartArea: false, 
							},
							title: {
								display: true,
								text: 'Accumulative',
							},
						},
					},
				},
			} as any;
			return d;
		},
	},
});
</script>
1reaction
mcelligottnickcommented, Nov 24, 2022

I’m glad mate!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create mixed chart types · Issue #29 - GitHub
From the chartjs docs: When creating the chart you must set the overall type as bar. So, try to use Chart.Bar.extend() ...
Read more >
How To Use Chart.js with Vue.js - DigitalOcean
With these two datasets, we can have different chart types to show correlations in data. Open your code editor and under src directory...
Read more >
vue-chartjs - npm
vue-chartjs is a wrapper for Chart.js in Vue. You can easily create reuseable chart components. Supports Chart.js v4. npm version codecov Build ...
Read more >
vue-chartjs examples - CodeSandbox
Learn how to use vue-chartjs by viewing and forking example apps that make use of vue-chartjs on CodeSandbox.
Read more >
Getting Started - vue-chartjs
Every chart type that is available in Chart.js is exported as a named component and can be imported as such. These components are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found