Version
4.7.0
Reproduction link
https://gallery.echartsjs.com/editor.html?c=xc4p47M_rM
Steps to reproduce
The canvas object use to measureText is no append to html document. so the style is no same to target canvas.
// https://github.com/ecomfe/zrender/blob/master/src/contain/text.js#L403
// Avoid assign to an exported variable, for transforming to cjs.
methods.measureText = function (text, font) {
var ctx = getContext();
ctx.font = font || DEFAULT_FONT;
return ctx.measureText(text);
};
// https://github.com/ecomfe/zrender/blob/master/src/core/util.js#L200
methods.createCanvas = function () {
return document.createElement('canvas');
};
local test code
incubator-echarts/test/testChart.html
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="lib/esl.js"></script>
<script src="lib/config.js"></script>
<script src="lib/jquery.min.js"></script>
<script src="lib/facePrint.js"></script>
<script src="lib/testHelper.js"></script>
</head>
<body>
<style>
body {
margin: 0;
font-variant: tabular-nums;
}
</style>
<div id="main" style="width: 360px;height:224px;border: 1px solid #000;"></div>
<script>
require([
'echarts'
], function (echarts) {
option = {
grid: {
left: 0,
top: 20,
right: 0,
bottom: 0,
"containLabel": true
},
"dataset": {
"source": [["key", "1", "2"], ["201904", "39.1087", "18403.0877"]],
},
"xAxis": {
"type": "category",
},
"yAxis": [{
"type": "value",
"axisLabel": {
"fontSize": 12,
"fontFamily": "BlinkMacSystemFont",
},
},
{
"type": "value",
"axisLabel": {
"fontSize": 12,
"fontFamily": "BlinkMacSystemFont",
},
}],
"series": [{
"type": "bar",
"barCategoryGap": "70%",
},
{
"type": "line",
"yAxisIndex": 1,
"symbol": "circle",
}]
};
myChart = echarts.init(document.getElementById('main'));
myChart.setOption(option);
});
</script>
</body>
</html>
What is expected?
measureText method can be calculate correctly
What is actually happening?
calculate label width error, when set special style to body (font-variant: tabular-nums;) and set label fontFamily:BlinkMacSystemFont
when I debug code in local, modify code as blow. it run correctly
// https://github.com/ecomfe/zrender/blob/master/src/core/util.js#L200
methods.createCanvas = function () {
const el = document.createElement('canvas');
el.style = "width:0px; height:0px;";
document.body.append(el);
return el;
};
3条答案
按热度按时间cotxawn71#
Hi! We've received your issue and please be patient to get responded. 🎉
The average response time is expected to be within one day for weekdays.
In the meanwhile, please make sure thatyou have posted enough image to demo your request. You may also check out the API and chart option to get the answer.
If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to dev@echarts.apache.org . Please attach the issue link if it's a technical questions.
If you are interested in the project, you may also subscribe our mail list .
Have a nice day! 🍵
ou6hu8tu2#
@lidianhao123 Would you like to submit PR to fix this issue?
ckx4rj1h3#
Looks like
BlinkMacSystemFont
caused the problem.