highcharts - 图例中的 Highstock Angular 值
问题描述
我正在寻找图例中插件值的替代品。该插件使用 jQuery,我正在运行 Angular 5 应用程序。以前有人为此创建过解决方案吗?
labelFormat: '<span style="color:{color}">{name}</span>: <b>{point.y:.2f} USD</b> ({point.change:.2f}%)<br/>'
这是使用 jQuery 访问图表容器并在图例上显示系列值的 Hicharts 示例。
解决方案
要摆脱 jquery,您可以在 chart.container 上jquery .bind
用 js 替换方法。addEventListener
接下来,遵循highcharts-angular 文档并为此插件创建自己的包装器。检查下面发布的演示。
Value-in-legend.js 插件:
(function(factory) {
if (typeof module === "object" && module.exports) {
module.exports = factory;
} else {
factory(Highcharts);
}
})(function(Highcharts) {
Highcharts.Series.prototype.point = {}; // The active point
Highcharts.Chart.prototype.callbacks.push(function(chart) {
chart.container.addEventListener("mousemove", function() {
var legendOptions = chart.legend.options,
hoverPoints = chart.hoverPoints;
// Return when legend is disabled (#4)
if (legendOptions.enabled === false) {
return;
}
if (!hoverPoints && chart.hoverPoint) {
hoverPoints = [chart.hoverPoint];
}
if (hoverPoints) {
Highcharts.each(hoverPoints, function(point) {
point.series.point = point;
});
Highcharts.each(chart.legend.allItems, function(item) {
item.legendItem.attr({
text: legendOptions.labelFormat
? Highcharts.format(legendOptions.labelFormat, item)
: legendOptions.labelFormatter.call(item)
});
});
chart.legend.render();
}
});
});
// Hide the tooltip but allow the crosshair
Highcharts.Tooltip.prototype.defaultFormatter = function() {
return false;
};
});
接下来,在您的组件中对其进行初始化:
require("./path-to-your-file/value-in-legend")(Highcharts);
推荐阅读
- python-3.x - 当我们放置较长的文本时,Keras Sequential 模型给出了不正确的预测
- php - 必应搜索 API 演示密钥是否有任何限制?
- android - 应用程序关闭时如何从服务器实时向安卓应用程序发送紧急警报?使用前台服务还是使用其他渠道?
- laravel - 在 laravel 中从多对多关系显示一个类别的许多产品
- mongodb - 是否可以通过 MongoDB 中的值查询字段名称?
- python - 重新排序python条形图
- python - 如何将一个较小 DataFrame 的值添加到另一个混合类型 DataFrame 的一部分,但仅添加到某个任意行索引之后的行?
- python - 将函数中的值放入上下文中
- java - 如何在 C++ 中捕获 sdbus::Error 异常?
- node.js - Windows但Mac上的Nodejs zlib gunzip“无效块类型”错误