[Chart:Pie]???????

2014-03-07 16:36:38by ???

饼图的渐进效果

说明

这篇文章介绍的是如何将饼图的颜色设为渐进色

思考

如下图是2010年特定网站下浏览器的市场份额,考虑以下几个重点

  1. 如何对每个已有的颜色进行渐进化处理

  2. 图中有一片是剥离状态的,如何实现。

  3. 图中数据标签的连接线都是黑色的,如何实现。

代码

// 替换颜色为渐进色
$A.Charts.getOptions().colors = Aurora.Charts.map(Aurora.Charts.getOptions().colors, function(color) {
    return {
        radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
        stops: [
            [0, color],
            [1, Aurora.Charts.Color(color).brighten(0.4).get('rgb')] 
        ]
    };
});

function formatter1(){
    return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
                
<a:dataSets>
    <a:dataSet id="ds">
        <a:datas>
            <a:record browser="Firefox" shares="45"/>
            <a:record browser="IE" shares="26.8"/>
            <a:record browser="Chrome" shares="12.8"/>
            <a:record browser="Safari" shares="8.5"/>
            <a:record browser="Opera" shares="6.2"/>
            <a:record browser="Others" shares="0.7"/>
        </a:datas>
        <a:fields>
            <a:field name="browser" prompt="浏览器"/>
            <a:field name="shares" datatype="float"  prompt="份额"/>
        </a:fields>
    </a:dataSet>
</a:dataSets>
<a:chart bindTarget="ds" type="pie" plotBackgroundColor="null" plotBorderWidth="null" plotShadow="false" >
    <a:title text="2010年特定网站下浏览器的市场份额"/>
    <a:tooltip pointFormat="{series.name}: &lt;b&gt;{point.percentage:.1f}%&lt;/b&gt;"/>
    <a:plotOptions>
        <a:pie allowPointSelect="true" cursor="pointer">
        	<a:dataLabels enabled="true" color="#000" connectorColor="#000" formatter="formatter1" />
        </a:pie>
    </a:plotOptions>
    <a:xAxis>
    	<a:xAxi name="browser" />
    </a:xAxis>
    <a:yAxis>
    	<a:yAxi name="shares" />
    </a:yAxis>
    <a:seriesList>
        <a:seriesItem name="shares">
        	<a:seriesDatas>
        		<a:seriesData dataIndex="2" sliced="true" selected="true"/>
        	</a:seriesDatas>
        </a:seriesItem>
    </a:seriesList>
</a:chart>

注释

  1. Aurora.Charts.map(array,callback)代码的意思是将array中的每个成员依次调用callback函数,然后返回所有callback执行的结果组成的数组。

  2. Aurora.Charts.Color(color).brighten(float).get('rgb')代码的意思是调整color颜色的量度。float取值范围-1~1,大于0是调亮,小于0是调暗。

Attachments
  1. ???????.rar

Comments

0 Responses to the article

暂时没有评论。

发表评论