如果把highcharts的主题放到自己的文件夹中方便修改,该怎么做呢?
新建一个主题的js文件
主题js的内容
代码语言:javascript复制import Highcharts from "highcharts/highcharts";
Highcharts.theme = {
colors: ['red', '#95C471', '#35729E', '#251735',"green"],
colorAxis: {
maxColor: '#05426E',
minColor: '#F3E796'
},
plotOptions: {
map: {
nullColor: '#FCFEFE'
}
},
navigator: {
maskFill: 'rgba(170, 205, 170, 0.5)',
series: {
color: '#95C471',
lineColor: '#35729E'
}
}
};
// Apply the theme
Highcharts.setOptions(Highcharts.theme);
最后在main.js中引入即可
代码语言:javascript复制import Highchart from "highcharts/highcharts";
import HighchartsVue from "highcharts-vue";
import stockInit from "highcharts/modules/stock";
import '@/assets/js/highchartsTheme/shine.js'
stockInit(Highchart);
Vue.use(HighchartsVue);
然后直接使用
代码语言:javascript复制<template>
<div>
<highcharts :options="chartOptions" :callback="myCallback"></highcharts>
</div>
</template>
<script>
export default {
name: "HelloWorld",
data() {
return {
chartOptions: {
//会覆盖主题里面定义的颜色
colors: ['black', '#95C471', '#35729E', '#251735',"green"],
title: {
text: "2010 ~ 2016 年太阳能行业就业人员发展情况"
},
subtitle: {
text: "数据来源:thesolarfoundation.com"
},
yAxis: {
title: {
text: "就业人数"
}
},
legend: {
layout: "vertical",
align: "right",
verticalAlign: "middle"
},
plotOptions: {
series: {
label: {
connectorAllowed: false
},
pointStart: 2010
}
},
series: [
{
name: "安装,实施人员",
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
},
{
name: "工人",
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
},
{
name: "销售",
data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
},
{
name: "项目开发",
data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227]
},
{
name: "其他",
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
}
],
responsive: {
rules: [
{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
layout: "horizontal",
align: "center",
verticalAlign: "bottom"
}
}
}
]
}
}
};
},
mounted() {
// 修改chartOptions里面的数据,在这里后台请求接口,返回的数据重新赋值
},
methods: {
myCallback() {
console.log("this is callback function");
}
}
};
</script>
<style>
.highcharts-container {
width: 600px;
height: 400px;
border: 1px solid #ddd;
margin: auto;
}
</style>