简体   繁体   English

Apache Echarts - 在轴名称上使用 webfont

[英]Apache Echarts - Use webfont on axis name

I'm trying to use a custom font when settings axis name(like on highcharts https://www.highcharts.com/forum/viewtopic.php?t=42108 ), for example fontawesome, so i can have something like this:我试图在设置轴名称时使用自定义字体(例如在 highcharts https://www.highcharts.com/forum/viewtopic.php?t=42108 上),例如 fontawesome,所以我可以有这样的东西:

option = {
    yAxis: {
        type: 'value',
        name: 'test' + String.fromCharCode(0xf111),
        nameTextStyle: {
            fontFamily: 'FontAwesome'
        }
    },
    series: [{
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line'
    }]
};

The YAxis name should be like 'test⏺', but unfortunately the font is not used and i get an unknown character. YAxis 名称应该类似于“test⏺”,但不幸的是未使用该字体并且我得到了一个未知字符。 => here => 这里

Do you have any idea how can this be done?你知道如何做到这一点吗?

Thanks ^_^谢谢^_^

another option could be use the background color configuration.另一种选择是使用背景颜色配置。 And the image element could be URL of a image or HTMLCanvasElement, which could be drawn awesomefont to it.并且图像元素可以是图像的 URL 或 HTMLCanvasElement,可以将其绘制成 awesomefont。

option = {
    yAxis: {
        type: 'value',
        name: 'text{x|  }',
        nameTextStyle: {
                    rich: {
                            x:{
                                backgroundColor: {
                                    image:'images/circle.png'
                                    // It can be URL of a image,
                                    // or dataURI,
                                    // or HTMLImageElement,
                                     // or HTMLCanvasElement. image: canvas 
                                }
                            }
                        }
                    }
    },
    series: [{
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line'
    }]
};

and here is an example to fill a canvas element with awesome font这是一个用很棒的字体填充画布元素的示例

var canvas = document.getElementById("your_canvasid");
var ctx = canvas.getContext('2d');

ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.font = '14px "FontAwesome"';
ctx.fillText('\uf111', 10, 10);

I have tested it works with image url, but i did not test with the canvas element...我已经测试过它适用于图像 url,但我没有使用 canvas 元素进行测试...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM