javascript - 导出 Highcharts 时无法根据需要禁用图例标题/启用图例标题
问题描述
我正在使用“highcharts”:“^6.1.2”,我修改了这样的图例标题
legend: {
layout: 'horizontal',
backgroundColor: '#FFFFFF',
align: 'left',
verticalAlign: 'top',
margin:35,
x: 90,
y:-25,
itemDistance: 50,
symbolHeight : 17,
symbolWidth : 17,
itemStyle : {
"fontFamily": "'Raleway', sans-serif !important",
"fontSize" : "14px !important",
},
title : {
text : "Filter by :",
style : {
"fontFamily": "'Raleway', sans-serif !important",
"fontSize" : "1rem !important",
"color" : "#5d737e !important",
"fontWeight": "500 !important",
}
}
},
也加载为
chart: {
type: 'area',
events: {
load: function(e) {
var title = this.legend.title;
title.translate(-83, 27);
},
redraw: function(e) {
var title = this.legend.title;
title.translate(-83, 27);
},
}
},
我需要下载并共享此图表,因为我添加了自定义按钮并使用了导出模块。
exporting: {
chartOptions: {
chart:{
events: {
load: function(e) {
var title = this.legend.title;
title.translate(-83, 27);
},
redraw: function(e) {
var title = this.legend.title;
title.translate(-83, 27);
},
}
},
legend: {
layout: 'horizontal',
backgroundColor: '#FFFFFF',
align: 'left',
verticalAlign: 'top',
margin:35,
x: 90,
y:-25,
itemDistance: 50,
symbolHeight : 17,
symbolWidth : 17,
itemStyle : {
"fontFamily": "'Raleway', sans-serif !important",
"fontSize" : "14px !important",
},
title : {
text : "Filter by :",
style : {
"fontFamily": "'Raleway', sans-serif !important",
"fontSize" : "1rem !important",
"color" : "#5d737e !important",
"fontWeight": "500 !important",
}
}
}
}
}
但是导出时图例标题显示不正确。它不会在自定义点击时应用。但如果我使用默认下载选项,则可以工作
这是js小提琴链接
查看图例标题位置
解决方案
您不能使用JSON.stringify
这些功能。您需要将图表发布为svg
:
$("#download").click(function() {
var obj = {};
...
obj.svg = chart.getSVG(chart.options);
...
});
现场演示: https ://jsfiddle.net/BlackLabel/u739oknb/
API 参考: https ://api.highcharts.com/class-reference/Highcharts.Chart#getSVG
推荐阅读
- javascript - Javascript:分配给函数内全局变量的值在函数外变为“未定义”
- ruby-on-rails - rails 如何在服务中使用带有 ERB.new 的助手?
- magento - magento 2 文档 CRUD
- c++ - 用于重新排序无符号整数的 Consexpr 可变参数模板
- java - 使用带有列表的java进行动态排序
- c - 保存mp4视频opencv
- time-series - 量化平稳的季节性
- c# - 将可选参数传递给方法
- php - 在嵌套属性 ElasticSearch 中添加和删除对象
- c - 为什么在 Linux 上的多线程中 sleep 不像 usleep 那样工作?