公司内部代码,因此只记录核心算法,方便以后查找,不喜勿看
/**
* 开始画饼图❀
*/
private function drawTrafficLightPlotChart():void {
currentPercent = 0;
// 删除之前的
for each(var chart:SkinnableContainer in this.voCharts) {
this.removeElement(chart);
}
this.voCharts.removeAll();
// 画每一项
for each(var vo:TrafficLightPlotChartVO in this.vos) {
drawTrafficLightPlotChartVO(vo, total);
}
currentPercent = 0;
}
/**
* 对每一项进行画饼图
* @param vo 包含底色、标签和量值的对象
* @param total 总共的数量
*/
private function drawTrafficLightPlotChartVO(vo:TrafficLightPlotChartVO, total:int):void {
var chart:SkinnableContainer = new SkinnableContainer();
// 获取该项数据所占比例
var percent:Number = vo.data/total * 100;
chart.toolTip = vo.label + ":" + vo.data + "s,占" + Math.round(percent) + "%";
// 开始画该项的区域
chart.graphics.lineStyle(1, vo.bgColor);
// 每0.25度画一次
for(var i:Number = 0;i < percent * 14.4;i++) {
chart.graphics.moveTo(centerX, centerY);
chart.graphics.lineTo(centerX + radius * Math.cos(currentPercent*Math.PI/180), centerY - radius * Math.sin(currentPercent*Math.PI/180));
currentPercent = currentPercent + 0.25;
}
this.addElement(chart);
this.voCharts.addItem(chart);
}
/**
* 根据比例画进度条
*/
private function drawAdjustProcess():void {
// 画每一项
for (var i:int = 0;i < this.vos.length;i++) {
drawProcess(this.vos[i], total, i);
}
currentProcess = 0;
// 画调节尺
for (var i:int = 0;i < this.vos.length;i++) {
addHand(this.vos[i], total, i);
}
this.addElement(this.adjustProcess);
}
/**
* 画进度条
*/
private function drawProcess(vo:TrafficLightPlotChartVO, total:int, index:int):void {
v