Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
计算机圆的X,Y坐标
function createXAxisCategories(){
//计算出弧
var canvas = $('#risk_report_polar_outside')[0];
var context = canvas.getContext('2d');
var width = canvas.width / 2;
var height = canvas.height / 2;
var radius = 230;
for(var i=0;i<categories.length;i++){
var angle = (2*Math.PI/360) * 22.5 * i;
var X = width + Math.sin(angle) * radius;
var Y = height - Math.cos(angle) * radius;
context.font="12px arial";
context.fillStyle="#ffffff";
//将位于中线上的Text居中
if(i === 0 || i === (categories.length/2) ) X -= (context.measureText(categories[i]).width / 2);
// 左侧上的文字因为默认会挡住圆
if(i >= 9) X -= context.measureText(categories[i]).width;
context.fillText(categories[i],X,Y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.