npm进行highchars的导入,导入完成后就可以进行highchars的可视化组件开发了

npm install highcharts --save

1、components目录下新建一个chart.vue组件

<template>
<div>
<div v-if="hasNoData()">
<p >{{ emptyText }}</p>
</div>
<div :id="id" v-else></div>
</div>
</template> <script>
import highcharts from 'highcharts'; export default {
props: {
id: {
type: String
},
config: {
data: {
required: true,
type: Array
},
colors: {
type: Array
},
option: {
type: Object
}
},
emptyText: {
default: '暂无数据'
}
},
data() {
return {
option: {
chart: {
type: 'column'
},
credits: {
enabled: false
},
title: {
text: null
},
xAxis: {
type: 'category',
tickWidth: 0
},
yAxis: {
visible: false
},
legend: {
enabled: false
},
...this.config.option,
plotOptions: {
column: {
colorByPoint: true,
colors: this.config.colors,
dataLabels: {
enabled: true
}
}
},
series: [{
data: this.config.data
}]
}
};
},
methods: {
hasNoData() {
if (this.config.data) {
return this.config.data.length > 0;
}
return true;
}
},
beforeDestroy() {
if (this.chart) {
this.chart.destroy();
}
},
created() {
},
mounted() {
if (!this.hasNoData()) {
this.chart = highcharts.chart(this.id, this.option);
}
}
};
</script>

2、chart组件建好后,开始创建chart-options目录,里面创建一个options.js用来存放模拟的chart数据

module.exports = {
bar: {
colors: ['#a7d7f6', '#7ec2ef', '#ffad57', '#f29260', '#f93d3b'],
data: [
['1号', 10],
['2号', 20],
['3号', 30],
['4号', 40],
['5号', 50]
],
option: {
tooltip: {
formatter: function () {
return `<span style="color:${this.color}">\u25CF</span> `;
}
}
}
}
}

3、引用chart组件

<template>
<div id="app">
<x-chart :id="id" :config="option" empty-text="暂无数据"></x-chart>
</div>
</template> <script>
// 导入chart组件
import XChart from 'components/chart.vue'
// 导入chart组件模拟数据
import options from './chart-options/options'
export default {
name: 'app',
data() {
let option = options.bar
return {
id: 'test',
option: option
}
},
components: {
XChart
}
}
</script> <style>
#test {
width: 400px;
height: 400px;
margin: 40px auto;
}
</style>

如果是Nuxt使用Highcharts的话,记得在nuxt.config..js里的build里vendor里写入highcharts以减少应用 bundle 的体积

嗯,就酱~~

参考  https://blog.csdn.net/lily2016n/article/details/75570716

在Nuxt中使用 Highcharts的更多相关文章

  1. 在nuxt中加入element-ui插件遇到的问题

    gen1.首先进入nuxt的官网跟着步骤实现内容. https://zh.nuxtjs.org/guide/plugins 2.在我们的项目目录中找plugin 根据图片中的表示引入内容: impor ...

  2. 在.NET MVC 中使用Highcharts+Ajax+Json生成动态曲线图,柱状图,饼图

    开发背景: 今天在做一个关于商城后台金额报表统计的功能,为了让数据直观明了并且这个报表还需要在手机端自适应所以我决定采用HIghCharts插件下的的报表,大家也可以去了解一下免费开源主要是好看. 首 ...

  3. 在vue中使用highcharts的仪表图等扩展

    仪表图(”solidgauge“)在highcharts中属于扩展,单独引入highcharts使用仪表图会报错,需要在你的组件中做一谢其他的引入: // 最主要是这里模块的引入 很坑 import ...

  4. React项目中使用HighCharts

    大家都知道BizCharts是基于react封装的一套图表工具,而HighCharts是基于jQuery的.但是由于本人对BizCharts甚是不熟,所以在react项目开发中选择了HighChart ...

  5. Angularjs中添加HighCharts

    一. 添加基本配置 1. 添加指令 angular.module('newApp') .directive('dpHighchart', ['$rootScope', function($rootSc ...

  6. axure中使用HighCharts模板制作统计图表

    一. 步骤: 1.在axure中新建页面,发布并生成html文件: 2.将HighCharts文件夹,拷贝到生成的html文件中: 3.拖拽“内部框架组件”到界面中 4.双击界面中的内部框架,设置链接 ...

  7. Nuxt中使用Vant,完成通知栏Notify的提示

    第一次移动端开发,UI方面选择了使用vant框架,但是vant官网写的使用,在nuxt项目中照搬官方的实例,各种报错,所以还得靠自己(使用方法在最后) 官方实例: 方法一:直接复制粘贴的时候,报错No ...

  8. 在nuxt中引入Font Awesome字体图标库

    介绍 在element-ui框架中提供了一些图标样式,但是种类比较少,所以在这里提供一套更完善的字体图标库Font Awesome(官方文档),下面就开始介绍如何在一个nuxt项目中使用这套字体库. ...

  9. nuxt中全局引入element-ui

    介绍 对于一个前端小白来说,使用一套已有的框架作为基础,可以达到事半功倍的效果,在这里我们选择Element.Element,一套为开发者.设计师和产品经理准备的基于 Vue 2.0 的桌面端组件库( ...

随机推荐

  1. SSH框架阶段 ——SSH的优缺点,使用场景?

    Hibernate优点: (1) 对象/关系数据库映射(ORM)它使用时只需要操纵对象,使开发更对象化,抛弃了数据库中心的思想,完全的面向对象思想(2) 透明持久化(persistent)带有持久化状 ...

  2. mongoDB 高级查询之复杂查询$where

    http://blog.csdn.net/drifterj/article/details/7833883

  3. 在CMD中查看端口被什么程序占用

    我们要查看端口被什么程序占用,可以使用下面方法.比如端口28848 1. 打开cmd,输入命令netstat -ano | findstr ":28848",显示结果如下,最后一个 ...

  4. curl 重定向问题

    今天在curl一个网站的时候遇到一个奇怪的问题,下面是输出: lxg@lxg-X240:~$ curl -L http://www.yngs.gov.cn/ -v * Hostname was NOT ...

  5. ssl中间证书

    中间证书,其实也叫中间CA(中间证书颁发机构,Intermediate certificate authority, Intermedia CA),对应的是根证书颁发机构(Root certifica ...

  6. Openlayer4 - 最好最强大的开源地图引擎

    Openlayer4 - 最好最强大的开源地图引擎 # githubhttps://github.com/openlayers/openlayers # 官网http://openlayers.org ...

  7. Mysql 没有nvl()函数,却有一个类似功能的函数ifnull()

    今天自己无聊写了看了一个查询需求随手写了一个sql语句,发现竟然不能运行,MySQL报[Err] 1305 - FUNCTION ceshi.nvl does not exist的错.才意识到自己写的 ...

  8. in App Purchases一个注意事项

    在completeTransaction中通过transaction.originalTransaction.payment.productIdentifier得到的productIdentifier ...

  9. useradd命令

    ◆useradd 1.作用 useradd命令用来建立用户帐号和创建用户的起始目录,使用权限是超级用户. 2.格式 useradd [-d home] [-s shell] [-c comment] ...

  10. Painting Fence

    Painting Fence Time Limit:1000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Sub ...