Code Monkey home page Code Monkey logo

vchart's Introduction

vchart

Vue Chartist.js Component

github npm npm npm size dep

浏览器版本: 3.78kb, GZip压缩后1.42kb

Usage / 使用说明

Installation / 安装

yarn add vchart
# or
npm i -S vchart

Props

  • ratio - String class ratio of Chartist. see values on / 参考: Chartist web site

  • type - String (required / 必选) chart type, possible values: / 支持的类型有:

    • Line
    • Bar
    • Pie
  • data - Object data object like this:

// 示例:
const data = {
    labels: ["A", "B", "C"],
    series:[[1, 3, 2], [4, 6, 5]]
}
  • options - Object options object, see defaultOptions on / 默认配置参考 API Documentation / API 文档

  • empty - String message when no data / 无数据时显示的文字消息

  • event-handlers - Array a special array to use chart.on(event, function)

// 处理 `chart.on(event, function)` 事件
const eventHandlers = [{
    event: 'draw',
    fn() {
        // animation / 动画
    }
}, {
    // an other event hander / 另一个事件处理器
}]
  • responsive-options - Array object for responsive options / 响应式参数对象

Example / 示例

Demo / 在线示例: https://vchart.js.cool/

Single File Components / 单文件组件中使用

<template>
<vchart
    ratio="ct-major-second"
    :type="type"
    :data="data"
    :options="options" >
</vchart>
</template>

<script>
import vchart from 'vchart';

exports default {
  components: {
    vchart
  },
  data() {
    return {
       data: {
            labels: ["周一", "周二", "周三", "周四", "周五"],
            series: [[4, 3.8, 3, 5, 4.1]]
        },
        type: 'Line',
        options: {
            fullWidth: true,
            lineSmooth: false
        }
    };
  }
}
</script>

Browser / 浏览器中使用

<!doctype html>
<html>
<head>
  <!-- Import CSS / 引用CSS -->
  <link rel="stylesheet" href="//unpkg.com/chartist/dist/chartist.css">
</head>
<body>

<!-- Example / 示例 -->
<div id="app">
  <vchart
      ratio="ct-major-second"
      :type="type"
      :data="chartData"
      :options="options" >
  </vchart>
</div>

<!-- Import Scripts / 引用JS资源 -->
<script src="//unpkg.com/vue"></script>
<script src="//unpkg.com/chartist"></script>
<script src="//unpkg.com/vchart"></script>
<script>
  new Vue({
    el: '#app',
    components: {
        vchart
    },
    data() {
        return {
            data: {
                labels: ["周一", "周二", "周三", "周四", "周五"],
                series: [[4, 3.8, 3, 5, 4.1]]
            },
            type: 'Line',
            options: {
                fullWidth: true,
                lineSmooth: false
            }
        }
    }
})
</script>
</body>
</html>

Animation / 动画

Demo / 演示: https://jsfiddle.net/willin/esvw0q91/

常用的三种动画:

  • dashoffset 跑马灯
  • bouncing-stroke 弹簧
  • exploding-stroke 爆炸
* {
  transform-origin: 0px 0px 0px;
}
.ct-line {
  stroke-dasharray: 5px;
  /* change animation name */
  animation: dashoffset 1s linear infinite;
}

@keyframes dashoffset  {
  0% {
    stroke-dashoffset: 0px;
  }

  100% {
    stroke-dashoffset: -20px;
  }
}

 @keyframes bouncing-stroke  {
  0% {
    stroke-width: 5px;
  }

  50% {
    stroke-width: 10px;
  }

  100% {
    stroke-width: 5px;
  }
}

@keyframes exploding-stroke  {
  0% {
    stroke-width: 2px;
    opacity: 1;
  }

  100% {
    stroke-width: 20px;
    opacity: 0;
  }
}

License

MIT

通过支付宝捐赠:

qr

vchart's People

Contributors

dependabot[bot] avatar willin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

shidongwa

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.