Skip to content
This repository has been archived by the owner on Dec 23, 2019. It is now read-only.

andreas2510/vue-c3js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vue-c3js

license

vue-c3js is a set of Vue components for creating charts easily, powered by c3js.

For the time being, many features of c3js are not supported. Feature requests are welcome.

Installation

npm install --save https://github.com/andreas2510/vue-c3js.git

Quick Start

Import the module in your main script.

import VueC3Js from 'vue-c3js'
Vue.use(VueC3Js)

Then use it within your HTML or vue template. At the very least, you need to specify the id of the component and also provide the chart data through one of the following props: columns, rows or json.

// In you script/vue template.
var columns = [
  ['data1', 30, 20, 50, 40, 60, 50],
  ['data2', 200, 130, 90, 240, 130, 220],
  ['data3', 300, 200, 160, 400, 250, 250],
  ['data4', 200, 130, 90, 240, 130, 220],
  ['data5', 130, 120, 150, 140, 160, 150],
  ['data6', 90, 70, 20, 50, 60, 120],
]
<!-- In your HTML/Vue template -->
<c3-bar-chart id="mychart" :columns="columns">

Example

Vue template

<template>
  <div id="app">
    <p>Welcome to your Vue.js app!</p>
    <c3-bar-chart id="mychart" :columns="columns">
  </div>
</template>

<script>
  export default {
    name: 'MainApp',
    data: {
      columns = [
        ['data1', 30, 20, 50, 40, 60, 50],
        ['data2', 200, 130, 90, 240, 130, 220],
        ['data3', 300, 200, 160, 400, 250, 250],
        ['data4', 200, 130, 90, 240, 130, 220],
        ['data5', 130, 120, 150, 140, 160, 150],
        ['data6', 90, 70, 20, 50, 60, 120],
      ]
    }
  }
</script>

HTML inline-template

Props

The idea is to pass configuration options to c3js through props. c3js has many options, not all of them are supported yet.

Chart options

Prop Name Type Description c3js docs
id String Required A string by which to identify the component. bindto
width Number The widht od the chart. size.width
height Number The widht od the chart. size.height
paddingTop Number paddingTop. padding.top
paddingRight Number paddingRight. padding.right
paddingBottom Number paddingBottom. padding.bottom
paddingLeft Number paddingLeft. padding.left
colorPattern Array colorPattern. color.pattern
disableInteraction Boolean disableInteraction. interaction.enabled
transitionDuration Number transitionDuration. transition.duration

Events

c3js events are passed through vue-c3js as standard vue events, which you can listen to in your script.

Chart events

Event Name Description c3js docs
oninit oninit. oninit
onrendered onrendered. onrendered
onmouseover onmouseover. onmouseover
onmouseout onmouseout. onmouseout
onresize onresize. onresize
onresized onresized. onresized

Data events

Event Name Description c3js docs
onclick onclick. data.onclick
onmouseover onmouseover. data.onmouseover
onmouseout onmouseout. data.onmouseout

Legend events

Event Name Description c3js docs
legend-onclick legend-onclick. legend.item.onclick
legend-onmouseover legend-onmouseover. legend.item.onmouseover
legend-onmouseout legend-onmouseout. legend.item.onmouseout

Zoom events

Event Name Description c3js docs
onzoom onzoom. zoom.onzoom
onzoomstart onzoomstart. zoom.onzoomstart
onzoomend onzoomend. zoom.onzoomend

Chart options

Id (String - Required)

<c3-bar-chart id="mychart">

Size (width and height)

<c3-bar-chart id="mychart" :rows="rows" width="480" height="320">

Padding (top, right, bottom, left)

<c3-bar-chart id="mychart" :rows="rows" padding-top="50" padding-right="50" padding-bottom="50" padding-left="50">

Color pattern (Array)

<c3-bar-chart id="mychart" :rows="rows" :color-pattern="['#1f77b4', '#aec7e8']">

Transition duration (Number)

Set duration of transition (in milliseconds) for chart animation.

<c3-bar-chart id="mychart" :rows="rows" transition-duration="1500">

Axis options

...

Grid options

...

Legend options

...

Tooltip options

...

Subchart options

...

Zoom options

...

Point options

...

Line options

...

Bar options

...

Gauge options

...

Pie options

...

Donut options

...

c3js options not currently supported

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published