Open Flash Chart 设置柱图宽度

本文介绍如何在图表中自定义柱状图的宽度,包括在BarBase.asa和Base.as文件中定义和设置barwidth变量的过程,以及在ScreenCoords.as文件中进行相应调整的方法。

1、修改文件charts/BarBase.as
a. 定义一个barwidth的protected变量

14
15
protected var on_show:Properties;
protected var barwidth:Number;

b. 往root变量加入barwidth默认值

20
21
22
23
24
25
26
27
28
29
30
var root:Properties = new Properties( {
    values:     [],
    colour:     '#3030d0',
    text:           '',     // <-- default not display a key
    'font-size':        12,
    tip:            '#val#<br>#x_label#',
    alpha:      0.6,
    'on-click':     false,
    'axis':         'left',
    barwidth:       10
} );

c. 获取并设置barwidth值

44
45
46
47
this.colour     = this.props.get_colour('colour');
this.key        = this.props.get('text');
this.font_size  = this.props.get('font-size');
this.barwidth   = this.props.get('barwidth');

d. 设置默认样式

116
117
118
119
120
121
122
123
124
var default_style:Properties = new Properties({
    colour: this.props.get('colour'),
    tip:        this.props.get('tip'),
    alpha:  this.props.get('alpha'),
    'on-click': this.props.get('on-click'),
    axis:       this.props.get('axis'),
    'on-show'this.on_show,
    barwidth:   this.props.get('barwidth')
});

2、编辑charts/series/Base.as文件
a. 添加protected 变量 barwidth

21
22
23
private var on_show_animate:Boolean;
protected var on_show:Properties;
protected var barwidth:Number;

b. 设置上述属性值

31
32
this.colour = props.get_colour('colour');
this.barwidth = props.get('barwidth');

c. 通过该属性计算获取宽度

126
var tmp:Object = sc.get_bar_coords(this.index, this.group, this.barwidth);

3、修改ScreenCoords.as文件
a. 上述已经修改传入变量barwidth,这里要添加一个接收其变量,默认值为0表示使用ofc自带。

327
public function get_bar_coords( index:Number, group:Number, barwidth:Number = 0 ):Object {

b. 加入以下代码设置宽度

331
332
333
var bar_set_width:Number = item_width * 0.8;
if ( barwidth && bar_set_width > barwidth * this.bar_groups )
    bar_set_width = barwidth * this.bar_groups;
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值