[英]How to add custom icons as markers in Highcharts
I need to use custom icons (in our case made by icomoon), as a markers inside charts. 我需要使用自定义图标(在本例中为icomoon制造)作为图表内的标记。
I tried what is explained here with font awesome icons, and it works: http://jsfiddle.net/highcharts/2A7Zf/ 我尝试使用字体真棒图标解释了这里的内容,并且可以正常工作: http : //jsfiddle.net/highcharts/2A7Zf/
However I need to provide our custom icons. 但是,我需要提供我们的自定义图标。
Our defined font-face is this: 我们定义的字体是这样的:
@font-face {
font-family: 'icomoon';
src: url("../webfonts/icomoon.eot?-nddtoy");
src: url("../webfonts/icomoon.eot?#iefix-nddtoy") format("embedded-opentype"), url("../webfonts/icomoon.woff?-nddtoy") format("woff"), url("../webfonts/icomoon.ttf?-nddtoy") format("truetype"), url("../webfonts/icomoon.svg?-nddtoy#icomoon") format("svg");
font-weight: normal;
font-style: normal;
}
[class^="icon-"], [class*=" icon-"] {
font-family: 'icomoon';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-star:before {
content: "\e976";
}
.icon-doc-filled:before {
content: "\e975";
}
.icon-camera:before {
content: "\e974";
}
Help is appreciated, how do I need to define font-face inside highcharts plugin for handling text symbols (shown in js fiddle) ? 感谢帮助,我如何在highcharts插件中定义字体来处理文本符号(如js小提琴所示)?
I solved it like this: 我这样解决了:
First, setup custom Highcharts plugin to handle text symbols shown below 首先,设置自定义Highcharts插件以处理如下所示的文本符号
import Highcharts from "highcharts";
/* Highcharts plugin to handle text symbols */
(function(H) {
function symbolWrap(proceed, symbol, x, y, w, h, options) {
if (symbol.indexOf("text:") === 0) {
var text = symbol.split(":")[1],
svgElem = this.text(text, x, y + h).css({
fontFamily: "icomoon", //icomoon fontFamily needed here
fontSize: h * 2
});
if (svgElem.renderer.isVML) {
svgElem.fillSetter = function(value, key, element) {
element.style.color = H.Color(value).get("rgb");
};
}
return svgElem;
}
return proceed.apply(this, [].slice.call(arguments, 1));
}
H.wrap(H.SVGRenderer.prototype, "symbol", symbolWrap);
if (H.VMLRenderer) {
H.wrap(H.VMLRenderer.prototype, "symbol", symbolWrap);
}
})(Highcharts);
export default Highcharts;
and if you code for font is e90c
, then in Highchart's marker object provide symbol like this: 并且如果您的字体代码是
e90c
,则在Highchart的标记对象中提供如下符号:
marker: {
symbol: 'text:\ue90c',
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.