Convert Figma logo to code with AI

apertureless logovue-chartjs

📊 Vue.js wrapper for Chart.js

5,530
834
5,530
34

Top Related Projects

64,568

Simple HTML5 Charts using the <canvas> tag

📊 Vue 2 component for ApexCharts

Vue.js component for Apache ECharts™.

Quick Overview

vue-chartjs is a wrapper for Chart.js in Vue.js. It provides easy-to-use components for creating various types of charts in Vue applications, allowing developers to leverage the power of Chart.js with the simplicity of Vue's component system.

Pros

  • Seamless integration with Vue.js components
  • Easy to use and implement in Vue projects
  • Supports all Chart.js chart types
  • Reactive data updates without the need for manual chart redraws

Cons

  • Limited to Chart.js functionality; custom chart types may be challenging
  • Learning curve for those unfamiliar with Chart.js
  • May have performance issues with large datasets
  • Documentation could be more comprehensive for advanced use cases

Code Examples

  1. Creating a simple line chart:
<template>
  <LineChart :chart-data="chartData" />
</template>

<script>
import { LineChart } from 'vue-chartjs'

export default {
  components: { LineChart },
  data() {
    return {
      chartData: {
        labels: ['January', 'February', 'March'],
        datasets: [
          {
            label: 'Data One',
            data: [40, 20, 12]
          }
        ]
      }
    }
  }
}
</script>
  1. Using mixins for chart options:
<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 {
  extends: Bar,
  props: ['chartData'],
  mounted() {
    this.renderChart(this.chartData, {
      responsive: true,
      maintainAspectRatio: false
    })
  }
}
</script>
  1. Reactive chart updates:
<template>
  <div>
    <button @click="addData">Add Data</button>
    <LineChart :chart-data="chartData" :options="chartOptions" />
  </div>
</template>

<script>
import { LineChart } from 'vue-chartjs'

export default {
  components: { LineChart },
  data() {
    return {
      chartData: {
        labels: ['January', 'February', 'March'],
        datasets: [{ data: [10, 20, 30] }]
      },
      chartOptions: {
        responsive: true
      }
    }
  },
  methods: {
    addData() {
      this.chartData.labels.push('April')
      this.chartData.datasets[0].data.push(40)
      this.$set(this.chartData, 'labels', this.chartData.labels)
      this.$set(this.chartData.datasets[0], 'data', this.chartData.datasets[0].data)
    }
  }
}
</script>

Getting Started

  1. Install the package:

    npm install vue-chartjs chart.js
    
  2. Import and use in your Vue component:

    <template>
      <LineChart :chart-data="chartData" />
    </template>
    
    <script>
    import { Line as LineChart } from 'vue-chartjs'
    import { Chart as ChartJS, Title, Tooltip, Legend, LineElement, LinearScale, CategoryScale, PointElement } from 'chart.js'
    
    ChartJS.register(Title, Tooltip, Legend, LineElement, LinearScale, CategoryScale, PointElement)
    
    export default {
      components: { LineChart },
      data() {
        return {
          chartData: {
            labels: ['January', 'February', 'March'],
            datasets: [{ data: [40, 20, 12] }]
          }
        }
      }
    }
    </script>
    

Competitor Comparisons

64,568

Simple HTML5 Charts using the <canvas> tag

Pros of Chart.js

  • More flexible and can be used with various frameworks or vanilla JavaScript
  • Larger community and ecosystem, leading to more resources and third-party plugins
  • Direct access to Chart.js features and updates without waiting for wrapper maintenance

Cons of Chart.js

  • Requires more setup and configuration when used with Vue.js
  • Less Vue-specific optimizations and integrations
  • May require additional work to make it reactive with Vue's data management

Code Comparison

Chart.js (vanilla JavaScript):

const ctx = document.getElementById('myChart').getContext('2d');
const chart = new Chart(ctx, {
    type: 'bar',
    data: chartData,
    options: chartOptions
});

vue-chartjs:

<bar-chart :chart-data="chartData" :options="chartOptions"></bar-chart>
import { Bar } from 'vue-chartjs'

export default {
  extends: Bar,
  mounted() {
    this.renderChart(this.chartData, this.chartOptions)
  }
}

vue-chartjs is a wrapper for Chart.js specifically designed for Vue.js applications. It provides a more Vue-centric approach to using Chart.js, with better integration into Vue's component system and reactivity. However, Chart.js offers more flexibility and can be used in a wider range of projects beyond Vue.js. The choice between the two depends on the specific needs of your project and your preference for Vue-specific tooling versus a more general-purpose charting library.

📊 Vue 2 component for ApexCharts

Pros of vue-apexcharts

  • More feature-rich with a wider variety of chart types and customization options
  • Better performance for large datasets and real-time updates
  • Active development with frequent updates and improvements

Cons of vue-apexcharts

  • Steeper learning curve due to more complex API and configuration options
  • Larger bundle size, which may impact initial load times for smaller projects

Code Comparison

vue-chartjs:

<script>
import { Bar } from 'vue-chartjs'

export default {
  extends: Bar,
  mounted() {
    this.renderChart(this.chartData, this.options)
  }
}
</script>

vue-apexcharts:

<template>
  <apexchart type="bar" :options="chartOptions" :series="series"></apexchart>
</template>

<script>
export default {
  data: () => ({
    chartOptions: { ... },
    series: [ ... ]
  })
}
</script>

vue-chartjs provides a simpler API with less boilerplate, while vue-apexcharts offers more granular control over chart configuration. vue-apexcharts uses a template-based approach, whereas vue-chartjs extends the chart component directly in the script section.

Both libraries have their strengths, with vue-chartjs being easier to get started with and vue-apexcharts offering more advanced features and customization options. The choice between them depends on the specific requirements of your project and the level of chart complexity needed.

Vue.js component for Apache ECharts™.

Pros of vue-echarts

  • More comprehensive and feature-rich, offering a wider range of chart types and customization options
  • Better performance for large datasets and complex visualizations
  • Stronger community support and more frequent updates

Cons of vue-echarts

  • Steeper learning curve due to its extensive API and configuration options
  • Larger bundle size, which may impact initial load times for smaller applications

Code Comparison

vue-echarts:

<template>
  <v-chart :option="option" />
</template>

<script>
import { use } from "echarts/core";
import { CanvasRenderer } from "echarts/renderers";
import { PieChart } from "echarts/charts";
import VChart from "vue-echarts";

use([CanvasRenderer, PieChart]);

export default {
  components: { VChart },
  data() {
    return {
      option: {
        series: [{
          type: 'pie',
          data: [/* ... */]
        }]
      }
    };
  }
};
</script>

vue-chartjs:

<template>
  <Pie :chart-data="chartData" />
</template>

<script>
import { Pie } from 'vue-chartjs';

export default {
  components: { Pie },
  data() {
    return {
      chartData: {
        labels: [/* ... */],
        datasets: [{
          data: [/* ... */]
        }]
      }
    };
  }
};
</script>

Both libraries offer Vue.js components for creating charts, but vue-echarts provides more flexibility and power at the cost of complexity, while vue-chartjs offers a simpler API for basic charting needs.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

vue-chartjs

vue-chartjs logo

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 Status Package Quality npm Gitter chat license CDNJS version Known Vulnerabilities Donate ko-fi


QuickStart   â€¢   Docs   â€¢   Stack Overflow

Quickstart

Install this library with peer dependencies:

pnpm add vue-chartjs chart.js
# or
yarn add vue-chartjs chart.js
# or
npm i vue-chartjs chart.js

Then, import and use individual components:

<template>
  <Bar :data="data" :options="options" />
</template>

<script lang="ts">
import {
  Chart as ChartJS,
  Title,
  Tooltip,
  Legend,
  BarElement,
  CategoryScale,
  LinearScale
} from 'chart.js'
import { Bar } from 'vue-chartjs'

ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend)

export default {
  name: 'App',
  components: {
    Bar
  },
  data() {
    return {
      data: {
        labels: ['January', 'February', 'March'],
        datasets: [{ data: [40, 20, 12] }]
      },
      options: {
        responsive: true
      }
    }
  }
}
</script>

Need an API to fetch data? Consider Cube, an open-source API for data apps.


supported by Cube

Docs

Build Setup

# install dependencies
pnpm install

# build for production with minification
pnpm build

# run unit tests
pnpm test:unit

# run all tests
pnpm test

Contributing

  1. Fork it ( https://github.com/apertureless/vue-chartjs/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

This software is distributed under MIT license.

Buy Me A Coffee

NPM DownloadsLast 30 Days