Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MixChart in documentation #1013

Open
1 task
djcaesar9114 opened this issue Mar 26, 2023 · 1 comment
Open
1 task

MixChart in documentation #1013

djcaesar9114 opened this issue Mar 26, 2023 · 1 comment

Comments

@djcaesar9114
Copy link

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?

There is no documentation on mixchart, for example when we want several line charts and one bar chart.

Describe the solution you'd like

I'd like an example to show how it's possible, as it's possible in chartJS, the basic library.

Describe alternatives you've considered

No response

Documentation, Adoption, Migration Strategy

No response

@ih84ds
Copy link

ih84ds commented Apr 9, 2023

I spent a few hours on this and finally ended up using this hack because I couldn't figure out how to properly extend the Bar chart in a way that allows it to accept 'bar' | 'line' data and options. The resulting chart does work as expected, but I'm not happy with the hack. Shirley, there has to be a better way...

<template>
  <bar-chart :data="mixedChartData" :options="mixedChartOptions"></bar-chart>
</template>

<script lang="ts">
import {
  BarController,
  BarElement,
  CategoryScale,
  Chart as ChartJS,
  ChartData,
  ChartOptions,
  LinearScale,
  LineController,
  LineElement,
  PointElement,
  Title,
  Tooltip,
} from 'chart.js';
import { computed, defineComponent, PropType } from 'vue';
import { Bar as BarChart } from 'vue-chartjs';

ChartJS.register(
  BarController,
  BarElement,
  CategoryScale,
  LinearScale,
  LineController,
  LineElement,
  PointElement,
  Title,
  Tooltip
);

export default defineComponent({
  name: 'BarAndLineChart',
  components: {
    BarChart,
  },
  props: {
    chartData: {
      type: Object as PropType<ChartData<'bar' | 'line'>>,
      required: true,
    },
    chartOptions: {
      type: Object as PropType<ChartOptions<'bar' | 'line'>>,
      required: true,
    },
  },
  setup(props) {
    const mixedChartData = computed(() => {
      // HACK ALERT! masquerading as ChartData<'bar'> so that the typed Bar chart doesn't freak out
      return props.chartData as ChartData<'bar'>;
    });
    const mixedChartOptions = computed(() => {
      // HACK ALERT! masquerading as ChartOptions<'bar'> so that the typed Bar chart doesn't freak out
      return props.chartOptions as ChartOptions<'bar'>;
    });

    return {
      mixedChartData,
      mixedChartOptions,
    };
  },
});
</script>

@palsingh palsingh mentioned this issue May 2, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants