下载插件
npm install highcharts-vue
npm install highcharts
安装插件
Vue.use(HighchartsVue)
使用
import { Chart } from 'highcharts-vue'
export default {
data () {
return {
chartOptions: {}
}
},
components: { Chart },
}
<highcharts :options="chartOptions"></highcharts>
图表组成
+-------------------------------------------+
| Highcharts 图表 |
+-------------------------------------------+
| 1. 容器(Container) |
| └─ HTML 元素(如 <div id="container"></div>) |
| 2. 标题(Title) |
| ├─ 主标题(Main Title) |
| └─ 副标题(Subtitle) |
| 3. 坐标轴(Axes) |
| ├─ X 轴(XAxis) |
| │ ├─ 轴标签(Axis Labels) |
| │ ├─ 轴线(Axis Line) |
| │ ├─ 分隔线(Tick Marks) |
| │ └─ 轴名称(Axis Title) |
| └─ Y 轴(YAxis) |
| ├─ 轴标签(Axis Labels) |
| ├─ 轴线(Axis Line) |
| ├─ 分隔线(Tick Marks) |
| └─ 轴名称(Axis Title) |
| 4. 网格(Grid) |
| └─ 背景网格线(Background Grid Lines) |
| 5. 数据系列(Series) |
| ├─ 系列类型(Series Type) |
| │ ├─ 折线图(Line) |
| │ ├─ 柱状图(Column) |
| │ ├─ 饼图(Pie) |
| │ └─ 散点图(Scatter) |
| ├─ 数据点(Data Points) |
| └─ 样式(Style) |
| ├─ 颜色(Color) |
| ├─ 线宽(Line Width) |
| └─ 标记符号(Marker Symbol) |
| 6. 图例(Legend) |
| ├─ 图例项(Legend Items) |
| └─ 布局(Layout) |
| 7. 提示框(Tooltip) |
| ├─ 触发方式(Trigger) |
| │ ├─ 悬停(Hover) |
| │ └─ 点击(Click) |
| └─ 格式化(Formatter) |
| 8. 数据标签(Data Labels) |
| ├─ 显示位置(Position) |
| └─ 格式化(Formatter) |
| 9. 导航器(Navigator) |
| └─ 时间序列缩放(Time Range Zoom) |
| 10. 导出功能(Exporting) |
| └─ 导出为图片/PDF(Export to Image/PDF) |
配置项说明
const option = {
chart: {
type: 'pie',
height: 300,
width: 600,
},
title: {
text: '图表标题',
align: 'center',
floating: false,
margin: 0,,
style: {}
userHTML: false,
verticalAlign: 'top',
minScale: 1,
x: 1,
y
},
subtitle: {
text: '图表副标题',
align: 'center',
floating: false,
style: {}
userHTML: false,
verticalAlign: 'top',
x: 1,
y
},
xAxis: {
accessibility: {
description: '对x轴的描述提供 X 轴的详细描述,屏幕阅读器会朗读该描述,帮助用户理解轴的含义',
enabled: undefined,
rangeDescription: '描述 X 轴的范围,例如时间跨度或数值范围'
},
type: 'datetime',
categories: ['Apples', 'Bananas', 'Oranges'],
title: {},
labels: {
overflow: 'justify',
enabled: true,
formatter: function() { return '自定义: ' + this.value; },
rotation: 0,
style: {} ,
}
},
yAxis: {
title: '',
labels: {
formatter: function () {
if (that.chartChoosed.indexOf('rate') > -1) {
return this.value + '%'
}
}
}
},
legend: {
enabled: false,
align: 'center',
backgroundColor: '',
},
tooltip: {
formatter: function(){
}
}
series: [
{
color: '',
type: 'spline',
name: this.optionsList.filter(item => item.value === that.chartChoosed)[0].label,
data: this.dataList.map(item => parseFloat(item[this.chartChoosed])),
accessibility: {},
allowPointSelect: true,
shadow: true,
}
],
}