Giter VIP home page Giter VIP logo

Comments (2)

alexanderbsd avatar alexanderbsd commented on May 22, 2024 1

Great, thank you!

from vue3-chartjs.

J-T-McC avatar J-T-McC commented on May 22, 2024

Hi Alexander.

I have updated your example with some random colour updates on a button click.

Edit*: also just a note that this looks like its for package version 0.3.0 and ChartJS 2.9.4. This will not work for version 1.0 and ChartJS 3 since they have changed the structure of their options. If you decide to move to version 1, there is a similar example in the src/App.vue for this library. You can clone the repo, install the packages and run yarn dev to try them out.

<template>
  <div style="height: 300px; width: 300px; border: 1px solid #000111">
    <Vue3ChartJS
        :id="lineChart.id"
        ref="chartRef"
        :type="lineChart.type"
        :data="lineChart.data"
        :options="lineChart.options"
    />
  </div>
  <button @click="update_Chart">Click Me</button>
</template>

<script>

import Vue3ChartJS from '@j-t-mcc/vue3-chartjs';
import { ref } from 'vue';

export default {
  components: {
    Vue3ChartJS,
  },
  setup() {

    const chartRef = ref(null)

    const new_number = ref(null);

    const dataSet = [
      {
        data: [40, 20, 80, 10],
      },
    ]

    const lineChart = {
      id: 'line-001',
      type: 'line',
      data: {
        labels: ["Vue", "A", "B", "C"],
        datasets: dataSet,
      },
      options: {
        maintainAspectRatio: false,
        responsive:true,
        scales: {
          yAxes: [{
            scaleLabel: {
              display: true,
              labelString: "Frequency (Hz)",
              fontFamily: "Montserrat",
              fontColor: "black",
            },
            ticks: {
              fontColor: "green",
              fontSize: 18,
              stepSize: 1,
              beginAtZero: true,
              min: -10,
              max: 120,
            }
          }],
          xAxes: [{
            ticks: {
              fontColor: "purple",
              fontSize: 14,
              stepSize: 1,
              beginAtZero: true
            }
          }]
        }

      }
    }

    const update_Chart= () => {
      lineChart.data.labels.push("N");
      lineChart.data.datasets[0].data.push(Math.random() * 100);
      lineChart.data.datasets[0].backgroundColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
      lineChart.data.datasets[0].borderColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
      lineChart.options.scales.yAxes[0].ticks.fontColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
      lineChart.options.scales.yAxes[0].scaleLabel.fontColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
      lineChart.options.scales.xAxes[0].ticks.fontColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
      lineChart.options.color = '#' + Math.floor(Math.random() * 16777215).toString(16);
      chartRef.value.update(500);
    }

    return {
      lineChart, new_number, update_Chart, chartRef
    }
  }

}
</script>

from vue3-chartjs.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.