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. 监听器如何获取Spring配置文件

    我们在做项目的时候,会用到监听器去获取spring的配置文件,然后从中拿出我们需要的bean出来,比如做网站首页,假设商品的后台业务逻辑都做好了,我们需要创建一个监听器,在项目启动时将首页的数据查询出 ...

  2. /u200B 8203 Zero-width space 问题

    [TestMethod] public void TestBom() { string str = "123​";//这个字符串是错误的有问题 长度4 ).Select(x =&g ...

  3. Scikit-learn的kmeans聚类

    1. 生成随机的二维数据: import numpy as np x1 = np.array([1, 2, 3, 1, 5, 6, 5, 5, 6, 7, 8, 9, 9]) x2 = np.arra ...

  4. TortoiseSVN客户端使用方法

    SVN对于程序开发来说是非常重要的东西,它是非常不错的版本管理工具,下面介绍一下TortoiseSVN客户端的使用方法. 工具/原料 TortoiseSVN 方法/步骤   如果没有TortoiseS ...

  5. VS2013-解决VS2013 4996错误

    由于微软在VS2013中不建议再使用C的传统库函数scanf,strcpy,sprintf等,所以直接使用这些库函数会提示C4996错误,在源文件中添加以下指令就可以避免这个错误提示. )

  6. Django学习之URLconf

    Django处理request的步骤: 1.确定根URLconf 2.载入urls.py,找到变量urlpatterns,urlpatterns是django.conf.urls.url()的实例对象 ...

  7. Chrome插件之一键保存网页为PDF1.1发布

    最新版本:V1.1 下载地址:http://download.csdn.net/detail/bdstjk/5722317 http://pan.baidu.com/share/link?sharei ...

  8. SpringMVC学习(一)小demo

    首先看一下整个demo的项目结构: 第一步是导入Spring MVC单独使用时的最少jar包: 第二步在项目的web.xml中配置Spring MVC提供的拦截请求的Servlet: 全类名是:org ...

  9. libubox组件(2)——blob/blobmsg (转载 https://segmentfault.com/a/1190000002391970)

    一:blob相关接口 1.数据结构 1: struct blob_attr { 2: uint32_t id_len; /** 高1位为extend标志,高7位存储id, 3: * 低24位存储dat ...

  10. 调试node.js应用--node-inspector

    如果你在编写Node.js代码,node-inspector是必备之选,比Node.js的内置调试器好出许多.使用起来跟Chrome的javascript调试器很相似. 使用npm安装: $ npm ...