AmChart 导出时更改字体颜色
AmChart export change font color on export
我遇到了问题并尝试了不同的解决方案,但没有成功。
我有一个 amChartXY 图表,它有白色标签,图例文本是白色的,但是当我想构建自定义 pdf 报告时,我无法将那些白色文本转换为黑色。
首先,我有一个将图表导出为 base64 字符串的函数,我想在那里将文本颜色转换为黑色,但它不起作用。
这是一个菜单项的代码片段,它转换为保存到全局数组对象的 SVG。
menu: [
{
class: "",
label: "Save to draft",
click: function() {
var overrideObject = {
backgroundColor : "rgba(255,255,255,1)",
color : "#000",
legend : {
color : "#000"
}
};
var chartObject = this;
chartObject.capture(overrideObject, function () {
chartObject.toJPG({}, function (base64) {
// charts is global array
charts.push({
name: customName,
chart: base64
});
});
});
}
},
此处 overrideObject
将 backgroundColor 属性更改为白色(之前是透明的),但未更改字体颜色。我也尝试添加不同的属性,但似乎没有任何效果。
这在捕获时可能吗?
这里有一些我想要完成的图片预览:
用于导出的 AmChart 没有很好的文档记录,因此欢迎任何反馈
您传递的 overrideObject 仅接受列出的相同参数 in the list of export settings. If you need to change the appearance of specific elements on the chart, you need to use the reviver
callback mentioned in the annotation settings section 以有选择地应用您的修改。例如,以下是定位值轴标签的方法:
"export": {
"enabled": true,
"reviver": function(nodeObj) {
if (nodeObj.className === 'amcharts-axis-label' && nodeObj.svg.parentNode.classList.contains('amcharts-value-axis')) {
nodeObj.fill = 'rgba(255,0,0,1)';
}
},
// ...
}
请注意,您需要使用 SVG 属性来更改外观,因此您必须设置填充以更改文本元素的颜色。
我遇到了问题并尝试了不同的解决方案,但没有成功。 我有一个 amChartXY 图表,它有白色标签,图例文本是白色的,但是当我想构建自定义 pdf 报告时,我无法将那些白色文本转换为黑色。 首先,我有一个将图表导出为 base64 字符串的函数,我想在那里将文本颜色转换为黑色,但它不起作用。 这是一个菜单项的代码片段,它转换为保存到全局数组对象的 SVG。
menu: [
{
class: "",
label: "Save to draft",
click: function() {
var overrideObject = {
backgroundColor : "rgba(255,255,255,1)",
color : "#000",
legend : {
color : "#000"
}
};
var chartObject = this;
chartObject.capture(overrideObject, function () {
chartObject.toJPG({}, function (base64) {
// charts is global array
charts.push({
name: customName,
chart: base64
});
});
});
}
},
此处 overrideObject
将 backgroundColor 属性更改为白色(之前是透明的),但未更改字体颜色。我也尝试添加不同的属性,但似乎没有任何效果。
这在捕获时可能吗?
这里有一些我想要完成的图片预览:
您传递的 overrideObject 仅接受列出的相同参数 in the list of export settings. If you need to change the appearance of specific elements on the chart, you need to use the reviver
callback mentioned in the annotation settings section 以有选择地应用您的修改。例如,以下是定位值轴标签的方法:
"export": {
"enabled": true,
"reviver": function(nodeObj) {
if (nodeObj.className === 'amcharts-axis-label' && nodeObj.svg.parentNode.classList.contains('amcharts-value-axis')) {
nodeObj.fill = 'rgba(255,0,0,1)';
}
},
// ...
}
请注意,您需要使用 SVG 属性来更改外观,因此您必须设置填充以更改文本元素的颜色。