Home > Web Front-end > JS Tutorial > Vue lightweight chart component

Vue lightweight chart component

Guanhui
Release: 2020-06-13 09:46:59
forward
3328 people have browsed it

Vue lightweight chart component

When encountering a scenario where charts need to be drawn on a web page, two libraries are generally used: D3.js and Chart.js. But in fact, you don't need such a heavyweight library at all. Sometimes you just want a simple SVG chart to meet your needs, then you can use Frappe Charts. It is a lightweight chart that provides full-featured, interactive animations, and with a simple component wrapper, you can use it with Vue.js!

Start installation

Start installing the component vue2-frappe. Here I assume you are working on an existing Vue.js project:

$ npm install --save vue2-frappe
Copy after login

Next step to register components:

import Vue from 'vue';
import VueFrappe from 'vue2-frappe';
import App from './App.vue';
Vue.use(VueFrappe);
new Vue({
  el: '#app',
  render: h => h(App)
});
Copy after login

Start drawing charts

vue2-frappe is a layer based on Frappe Charts, encapsulating it for use with Vue.js Components, please see the Frappe Chart documentation for more usage:

<template>
  <div id="app">
    <h2>Chart: Benedict&#39;s Weight</h2>
    <!-- id - 每一个图表必须有一个 id. -->
    <!-- title - 图表上方显示的标题 -->
    <!-- type - 图表的类型 线性图、饼图、条形图、等 -->
    <!-- labels - x 轴上的值 -->
    <!-- height- 可选,图表的高度 -->
    <!-- colors - 将每一个数据集进行颜色区分 -->
    <!-- lineOptions - 线形图的更多选项,请见文档-->
    <!-- datasets - 数据集,对象数组 -->
    <vue-frappe
      id="my-chart-id"
      title="Benedict&#39;s Weight From 2017-2018 (lbs)"
      type="line"
      :labels="[&#39;Jan&#39;, &#39;Feb&#39;, &#39;Mar&#39;, &#39;Apr&#39;, &#39;May&#39;, &#39;Jun&#39;, &#39;Jul&#39;, &#39;Aug&#39;, &#39;Sep&#39;, &#39;Oct&#39;, &#39;Nov&#39;, &#39;Dec&#39;]"
      :height="650"
      :colors="[&#39;#008F68&#39;, &#39;#FAE042&#39;]"
      :lineOptions="{regionFill: 1}"
      :datasets="[
        {name: &#39;2017&#39;, values: benedictsWeight2017},
        {name: &#39;2018&#39;, values: benedictsWeight2018}
      ]"
    ></vue-frappe>
    <p>Conclusion: Benedict needs to go on a diet.</p>
  </div>
</template>
<script>
export default {
  name: &#39;app&#39;,
  data() {
    return {
      benedictsWeight2017: [480, 485, 491, 489, 485, 490, 497, 510, 512, 521, 530, 545],
      benedictsWeight2018: [540, 575, 570, 555, 572, 580, 585, 587, 588, 590, 592, 590]
    }
  }
}
</script>
Copy after login

Frappe Charts supports a variety of icons, such as pie charts, bar charts, proportion charts, heat maps, etc., for more advanced displays options, please see its official documentation!

Recommended tutorial: "JS Tutorial"

The above is the detailed content of Vue lightweight chart component. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template