vue+highcharts的基本图标使用

hightcharts官网网址:Highcharts网址

步骤一:在创建的vue项目中 安装npm包

npm install highcharts --save

步骤二:在main.js文件中import相关包 

import Highcharts from 'highcharts/highstock';
import HighchartsMore from 'highcharts/highcharts-more';
HighchartsMore(Highcharts);

步骤三:找到components组件文件夹,写一个chart.vue组件 ,代码如下

<template>
  		<div>
    		<div :id="id"  :option="option"></div>
  		</div>
</template>
<script>
import HighCharts from 'highcharts'
export default {
 	props: {
   		id: {
   		     type: String
  			},
    	option: {
    	     type: Object
   			}
  		},
  	mounted() {
   		HighCharts.chart(this.id,this.option)
 		}
	}
</script>

步骤四:找到要使用图标的页面,引入chart组件,在页面中写入如下代码:

<template>
  <div id="container" style="width: 400px; height: 400px">
    <hchart></hchart>
  </div>
</template>
<script>
import hchart from "@/components/chart";
import HighCharts from "highcharts";
export default {
  mounted() {
    HighCharts.chart("container", this.option);
  },
  components: {
    hchart,
  },
  data() {
    return {
      option: {
       //写入配置数据
      },
    };
  },
};
</script>

饼图示例:

<template>
  <div id="container" style="width: 400px; height: 400px">
    <hchart></hchart>
  </div>
</template>
<script>
import hchart from "@/components/chart";
import HighCharts from "highcharts";
export default {
  mounted() {
    HighCharts.chart("container", this.option);
  },
  components: {
    hchart,
  },
  data() {
    return {
      option: {
        chart: {
          plotBackgroundColor: null,
          plotBorderWidth: null,
          plotShadow: false,
          type: "pie",
        },
        title: {
          text: "2018 年浏览器市场份额",
        },
        tooltip: {
          pointFormat: "{series.name}: <b>{point.percentage:.1f}%</b>",
        },
        plotOptions: {
          pie: {
            allowPointSelect: true,
            cursor: "pointer",
            dataLabels: {
              enabled: false,
            },
            showInLegend: true,
          },
        },
        series: [
          {
            name: "Brands",
            colorByPoint: true,
            data: [
              {
                name: "Chrome",
                y: 61.41,
                sliced: true,
                selected: true,
              },
              {
                name: "Internet Explorer",
                y: 11.84,
              },
              {
                name: "Firefox",
                y: 10.85,
              },
              {
                name: "Edge",
                y: 4.67,
              },
              {
                name: "Safari",
                y: 4.18,
              },
              {
                name: "Other",
                y: 7.05,
              },
            ],
          },
        ],
      },
    };
  },
};
</script>

结果展示:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值