• Stars
    star
    747
  • Rank 60,741 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create beautiful JavaScript charts with one line of Vue

Vue Chartkick

Create beautiful JavaScript charts with one line of Vue

See it in action

Supports Chart.js, Google Charts, and Highcharts

Build Status

Quick Start

Run

npm install vue-chartkick chart.js

The latest version works with Vue 3. For Vue 2, use version 0.6.1 and this readme.

And add it to your app

import VueChartkick from 'vue-chartkick'
import 'chartkick/chart.js'

app.use(VueChartkick)

This sets up Chartkick with Chart.js. For other charting libraries, see detailed instructions.

Charts

Line chart

<line-chart :data="{'2021-01-01': 11, '2021-01-02': 6}"></line-chart>

Pie chart

<pie-chart :data="[['Blueberry', 44], ['Strawberry', 23]]"></pie-chart>

Column chart

<column-chart :data="[['Sun', 32], ['Mon', 46], ['Tue', 28]]"></column-chart>

Bar chart

<bar-chart :data="[['Work', 32], ['Play', 1492]]"></bar-chart>

Area chart

<area-chart :data="{'2021-01-01': 11, '2021-01-02': 6}"></area-chart>

Scatter chart

<scatter-chart :data="[[174.0, 80.0], [176.5, 82.3]]" xtitle="Size" ytitle="Population"></scatter-chart>

Geo chart - Google Charts

<geo-chart :data="[['United States', 44], ['Germany', 23], ['Brazil', 22]]"></geo-chart>

Timeline - Google Charts

<timeline :data="[['Washington', '1789-04-29', '1797-03-03'], ['Adams', '1797-03-03', '1801-03-03']]"></timeline>

Multiple series

data = [
  {name: 'Workout', data: {'2021-01-01': 3, '2021-01-02': 4}},
  {name: 'Call parents', data: {'2021-01-01': 5, '2021-01-02': 3}}
];

and

<line-chart :data="data"></line-chart>

Data

Data can be an array, object, callback, or URL.

Array

<line-chart :data="[['2021-01-01', 2], ['2021-01-02', 3]]"></line-chart>

Object

<line-chart :data="{'2021-01-01': 2, '2021-01-02': 3}"></line-chart>

Callback

function fetchData(success, fail) {
  success({"2021-01-01": 2, "2021-01-02": 3})
  // or fail("Data not available")
}

and

<line-chart :data="fetchData"></line-chart>

URL

Make your pages load super fast and stop worrying about timeouts. Give each chart its own endpoint.

<line-chart data="/stocks"></line-chart>

Options

Id, width, and height

<line-chart id="users-chart" width="800px" height="500px"></line-chart>

Min and max values

<line-chart :min="1000" :max="5000"></line-chart>

min defaults to 0 for charts with non-negative values. Use null to let the charting library decide.

Min and max for x-axis - Chart.js

<line-chart xmin="2021-01-01" xmax="2022-01-01"></line-chart>

Colors

<line-chart :colors="['#b00', '#666']"></line-chart>

Stacked columns or bars

<column-chart :stacked="true"></column-chart>

Discrete axis

<line-chart :discrete="true"></line-chart>

Label (for single series)

<line-chart label="Value"></line-chart>

Axis titles

<line-chart xtitle="Time" ytitle="Population"></line-chart>

Straight lines between points instead of a curve

<line-chart :curve="false"></line-chart>

Show or hide legend

<line-chart :legend="true"></line-chart>

Specify legend position

<line-chart legend="bottom"></line-chart>

Donut chart

<pie-chart :donut="true"></pie-chart>

Prefix, useful for currency - Chart.js, Highcharts

<line-chart prefix="$"></line-chart>

Suffix, useful for percentages - Chart.js, Highcharts

<line-chart suffix="%"></line-chart>

Set a thousands separator - Chart.js, Highcharts

<line-chart thousands=","></line-chart>

Set a decimal separator - Chart.js, Highcharts

<line-chart decimal=","></line-chart>

Set significant digits - Chart.js, Highcharts

<line-chart :precision="3"></line-chart>

Set rounding - Chart.js, Highcharts

<line-chart :round="2"></line-chart>

Show insignificant zeros, useful for currency - Chart.js, Highcharts

<line-chart :round="2" :zeros="true"></line-chart>

Friendly byte sizes - Chart.js 2.8+

<line-chart :bytes="true"></line-chart>

Specify the message when the chart is loading

<line-chart loading="Loading..."></line-chart>

Specify the message when data is empty

<line-chart empty="No data"></line-chart>

Refresh data from a remote source every n seconds

<line-chart :refresh="60"></line-chart>

You can pass options directly to the charting library with:

<line-chart :library="{backgroundColor: '#eee'}"></line-chart>

See the documentation for Google Charts, Highcharts, and Chart.js for more info.

To customize datasets in Chart.js, use:

<line-chart :dataset="{borderWidth: 10}"></line-chart>

You can pass this option to individual series as well.

Use dynamic components to make the chart type dynamic:

<component is="column-chart"></component>

Reactivity

While some of the examples use object or array literals in props for demonstration, this can lead to unnecessary re-renders.

<line-chart :library="{backgroundColor: '#eee'}"></line-chart>

Instead, use a data property:

<line-chart :library="library"></line-chart>

See this discussion for more details.

Global Options

To set options for all of your charts, use:

Chartkick.options = {
  colors: ["#b00", "#666"]
}

Multiple Series

You can pass a few options with a series:

  • name
  • data
  • color
  • dataset - Chart.js only
  • points - Chart.js only
  • curve - Chart.js only

Download Charts

Chart.js only

Give users the ability to download charts. It all happens in the browser - no server-side code needed.

<line-chart :download="true"></line-chart>

Set the filename

<line-chart download="boom"></line-chart>

Note: Safari will open the image in a new window instead of downloading.

Set the background color

<line-chart :download="{background: '#fff'}"></line-chart>

Installation

Chart.js

Run

npm install vue-chartkick chart.js

And add

import VueChartkick from 'vue-chartkick'
import 'chartkick/chart.js'

app.use(VueChartkick)

Google Charts

Run

npm install vue-chartkick

And add

import VueChartkick from 'vue-chartkick'

app.use(VueChartkick)

And include on the page

<script src="https://www.gstatic.com/charts/loader.js"></script>

To specify a language or Google Maps API key, use:

Chartkick.configure({language: "de", mapsApiKey: "..."})

Highcharts

Run

npm install vue-chartkick highcharts

And add

import VueChartkick from 'vue-chartkick'
import 'chartkick/highcharts'

app.use(VueChartkick)

No Package Manager

Include the charting library and the Chartkick library

<script src="https://unpkg.com/[email protected]/dist/chart.umd.js"></script>
<script src="https://unpkg.com/[email protected]/dist/chartjs-adapter-date-fns.bundle.js"></script>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/[email protected]"></script>

And add

app.use(VueChartkick)

Multiple Libraries

If more than one charting library is loaded, choose between them with:

<line-chart adapter="google"></line-chart>

Options are google, highcharts, and chartjs

Example

<div id="app">
  <line-chart :data="chartData"></line-chart>
</div>

<script>
  var app = Vue.createApp({
    el: "#app",
    data: {
      chartData: [["Jan", 4], ["Feb", 2], ["Mar", 10], ["Apr", 5], ["May", 3]]
    }
  })
  app.use(VueChartkick)
  app.mount("#app")
</script>

Upgrading

1.0

Vue Chartkick 1.0 adds support for Vue 3. Vue 3 requires you to specify plugins for each app.

Vue.use(Chartkick.use(Chart))

to

app.use(Chartkick.use(Chart))

For the no package manager install, Chartkick.js is no longer bundled, allowing you to update them independently. Include it manually before Vue Chartkick.

<script src="https://unpkg.com/[email protected]/dist/chartkick.js"></script>

Finally, Vue Chartkick no longer uses custom logic to see if a re-render is necessary. See the reactivity docs for more details.

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development, run:

git clone https://github.com/ankane/vue-chartkick.git
cd vue-chartkick
npm install
npm run build

More Repositories

1

pghero

A performance dashboard for Postgres
Ruby
7,123
star
2

searchkick

Intelligent search made easy
Ruby
6,257
star
3

chartkick

Create beautiful JavaScript charts with one line of Ruby
Ruby
6,157
star
4

blazer

Business intelligence made simple
Ruby
4,511
star
5

ahoy

Simple, powerful, first-party analytics for Rails
Ruby
3,872
star
6

strong_migrations

Catch unsafe migrations in development
Ruby
3,662
star
7

groupdate

The simplest way to group temporal data
Ruby
3,617
star
8

pgsync

Sync data from one Postgres database to another
Ruby
2,787
star
9

the-ultimate-guide-to-ruby-timeouts

Timeouts for popular Ruby gems
Ruby
2,212
star
10

production_rails

Best practices for running Rails in production
1,975
star
11

dexter

The automatic indexer for Postgres
Ruby
1,491
star
12

lockbox

Modern encryption for Ruby and Rails
Ruby
1,290
star
13

chartkick.js

Create beautiful charts with one line of JavaScript
JavaScript
1,211
star
14

react-chartkick

Create beautiful JavaScript charts with one line of React
JavaScript
1,183
star
15

pretender

Log in as another user in Rails
Ruby
1,124
star
16

ahoy_email

First-party email analytics for Rails
Ruby
1,051
star
17

secure_rails

Rails security best practices
954
star
18

pgslice

Postgres partitioning as easy as pie
Ruby
953
star
19

mailkick

Email subscriptions for Rails
Ruby
847
star
20

eps

Machine learning for Ruby
Ruby
609
star
21

awesome-legal

Awesome free legal documents for companies
589
star
22

searchjoy

Search analytics made easy
Ruby
579
star
23

polars-ruby

Blazingly fast DataFrames for Ruby
Ruby
563
star
24

torch.rb

Deep learning for Ruby, powered by LibTorch
Ruby
552
star
25

blind_index

Securely search encrypted database fields
Ruby
470
star
26

safely

Rescue and report exceptions in non-critical code
Ruby
470
star
27

authtrail

Track Devise login activity
Ruby
466
star
28

multiverse

Multiple databases for Rails πŸŽ‰
Ruby
463
star
29

ahoy.js

Simple, powerful JavaScript analytics
JavaScript
463
star
30

hightop

A nice shortcut for group count queries
Ruby
462
star
31

field_test

A/B testing for Rails
Ruby
460
star
32

s3tk

A security toolkit for Amazon S3
Python
439
star
33

disco

Recommendations for Ruby and Rails using collaborative filtering
Ruby
431
star
34

active_median

Median and percentile for Active Record, Mongoid, arrays, and hashes
Ruby
427
star
35

informers

State-of-the-art natural language processing for Ruby
Ruby
417
star
36

notable

Track notable requests and background jobs
Ruby
402
star
37

shorts

Short, random tutorials and posts
379
star
38

tensorflow-ruby

Deep learning for Ruby
Ruby
350
star
39

distribute_reads

Scale database reads to replicas in Rails
Ruby
328
star
40

slowpoke

Rack::Timeout enhancements for Rails
Ruby
327
star
41

prophet-ruby

Time series forecasting for Ruby
Ruby
321
star
42

rover

Simple, powerful data frames for Ruby
Ruby
311
star
43

groupdate.sql

The simplest way to group temporal data
PLpgSQL
280
star
44

kms_encrypted

Simple, secure key management for Lockbox and attr_encrypted
Ruby
235
star
45

jetpack

A friendly package manager for R
R
234
star
46

neighbor

Nearest neighbor search for Rails and Postgres
Ruby
230
star
47

rollup

Rollup time-series data in Rails
Ruby
230
star
48

hypershield

Shield sensitive data in Postgres and MySQL
Ruby
227
star
49

logstop

Keep personal data out of your logs
Ruby
218
star
50

pdscan

Scan your data stores for unencrypted personal data (PII)
Go
213
star
51

delete_in_batches

Fast batch deletes for Active Record and Postgres
Ruby
202
star
52

vega-ruby

Interactive charts for Ruby, powered by Vega and Vega-Lite
Ruby
192
star
53

mapkick

Create beautiful JavaScript maps with one line of Ruby
Ruby
173
star
54

dbx

A fast, easy-to-use database library for R
R
171
star
55

fastText-ruby

Efficient text classification and representation learning for Ruby
Ruby
162
star
56

autosuggest

Autocomplete suggestions based on what your users search
Ruby
162
star
57

swipeout

Swipe-to-delete goodness for the mobile web
JavaScript
159
star
58

pghero.sql

Postgres insights made easy
PLpgSQL
154
star
59

mainstreet

Address verification for Ruby and Rails
Ruby
149
star
60

or-tools-ruby

Operations research tools for Ruby
Ruby
139
star
61

mapkick.js

Create beautiful, interactive maps with one line of JavaScript
JavaScript
138
star
62

trend-ruby

Anomaly detection and forecasting for Ruby
Ruby
128
star
63

mitie-ruby

Named-entity recognition for Ruby
Ruby
122
star
64

barkick

Barcodes made easy
Ruby
120
star
65

ownership

Code ownership for Rails
Ruby
111
star
66

anomaly

Easy-to-use anomaly detection for Ruby
Ruby
98
star
67

errbase

Common exception reporting for a variety of services
Ruby
87
star
68

tokenizers-ruby

Fast state-of-the-art tokenizers for Ruby
Rust
81
star
69

ip_anonymizer

IP address anonymizer for Ruby and Rails
Ruby
79
star
70

str_enum

String enums for Rails
Ruby
75
star
71

faiss-ruby

Efficient similarity search and clustering for Ruby
C++
73
star
72

trend-api

Anomaly detection and forecasting API
R
71
star
73

archer

Rails console history for Heroku, Docker, and more
Ruby
70
star
74

onnxruntime-ruby

Run ONNX models in Ruby
Ruby
70
star
75

xgboost-ruby

High performance gradient boosting for Ruby
Ruby
69
star
76

secure-spreadsheet

Encrypt and password protect sensitive CSV and XLSX files
JavaScript
66
star
77

active_hll

HyperLogLog for Rails and Postgres
Ruby
66
star
78

guess

Statistical gender detection for Ruby
Ruby
60
star
79

morph

An encrypted, in-memory, key-value store
C++
59
star
80

lightgbm-ruby

High performance gradient boosting for Ruby
Ruby
56
star
81

midas-ruby

Edge stream anomaly detection for Ruby
Ruby
54
star
82

moves

Ruby client for Moves
Ruby
54
star
83

blingfire-ruby

High speed text tokenization for Ruby
Ruby
54
star
84

vowpalwabbit-ruby

Fast online machine learning for Ruby
Ruby
52
star
85

xlearn-ruby

High performance factorization machines for Ruby
Ruby
51
star
86

tomoto-ruby

High performance topic modeling for Ruby
C++
51
star
87

trove

Deploy machine learning models in Ruby (and Rails)
Ruby
50
star
88

mapkick-static

Create beautiful static maps with one line of Ruby
Ruby
42
star
89

ahoy_events

Simple, powerful event tracking for Rails
Ruby
42
star
90

practical-search

Let’s make search a better experience for our users
40
star
91

breakout-ruby

Breakout detection for Ruby
Ruby
40
star
92

plu

Price look-up codes made easy
Ruby
40
star
93

ngt-ruby

High-speed approximate nearest neighbors for Ruby
Ruby
39
star
94

gindex

Concurrent index migrations for Rails
Ruby
39
star
95

clockwork_web

A web interface for Clockwork
Ruby
38
star
96

ahoy_guide

A foundation of knowledge and libraries for solid analytics
38
star
97

notable_web

A web interface for Notable
HTML
36
star
98

AnomalyDetection.rb

Time series anomaly detection for Ruby
Ruby
34
star
99

khiva-ruby

High-performance time series algorithms for Ruby
Ruby
34
star
100

immudb-ruby

Ruby client for immudb, the immutable database
Ruby
34
star