Skip to content
Snippets Groups Projects
Select Git revision
  • main
1 result

BarChart.vue

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    BarChart.vue 1.78 KiB
    <script>
    import { Bar } from "vue-chartjs";
    import {
      Chart as ChartJS,
      Title,
      Tooltip,
      Legend,
      BarElement,
      CategoryScale,
      LinearScale,
    } from "chart.js";
    ChartJS.register(
      Title,
      Tooltip,
      Legend,
      BarElement,
      CategoryScale,
      LinearScale
    );
    
    export default {
      name: "BarChart",
      components: { Bar },
      props: {
        chartId: {
          type: String,
          default: "bar-chart",
        },
        datasetIdKey: {
          type: String,
          default: "label",
        },
        width: {
          type: Number,
          default: 400,
        },
        height: {
          type: Number,
          default: 190,
        },
        cssClasses: {
          default: "",
          type: String,
        },
        styles: {
          type: Object,
          default: () => {},
        },
        plugins: {
          type: Array,
          default: () => [],
        },
        chartData: {
          type: Object,
        },
        customTickCallback: {
          type: Function,
          default: undefined,
        },
      },
      data(props) {
        return {
          chartOptions: {
            responsive: true,
            plugins: {
              legend: {
                display: false,
              },
            },
            scales: {
              x: {
                ticks: {
                  color: "white",
                },
                grid: {
                  color: "#ffffff33",
                },
              },
              y: {
                ticks: {
                  color: "white",
                  callback: props.customTickCallback ? props.customTickCallback : undefined,
                },
                grid: {
                  color: "#ffffff33",
                },
              }
            },
          },
        };
      },
    };
    </script>
    
    <template>
      <Bar
        :chart-options="chartOptions"
        :chart-data="chartData"
        :chart-id="chartId"
        :dataset-id-key="datasetIdKey"
        :plugins="plugins"
        :css-classes="cssClasses"
        :styles="styles"
        :height="height"
      />
    </template>