开发者

How to add labels to horizontal axis in Flex

开发者 https://www.devze.com 2023-04-11 22:36 出处:网络
I am using a Column Chart to display certain data. The data is provided by an array collection. The array contains 3 elements for the horizontal axis, hence 3 labels are shown on the horizontal axis.

I am using a Column Chart to display certain data. The data is provided by an array collection. The array contains 3 elements for the horizontal axis, hence 3 labels are shown on the horizontal axis. I want to show 2 additional labels(i.e. total 5 labels) dynamically on the chart. I th开发者_Python百科ere a way to add labels to the horizontal axis.

 public var expenses:ArrayCollection = new ArrayCollection([
    {Month:"Jan", Revenue:1200, Expenses:500},
    {Month:"Feb", Revenue:1200, Expenses:550},
    {Month:"Mar", Revenue:1240, Expenses:475},
 ]);

/////////////////////////////////////////////////////////

<s:Panel title="Floating Column Chart">
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
     <mx:ColumnChart 
        dataProvider="{expenses}" 
        showDataTips="true">
        <mx:horizontalAxis>
           <mx:CategoryAxis 
                dataProvider="{expenses}" 
                categoryField="Month"/>
        </mx:horizontalAxis>
        <mx:series>
           <mx:ColumnSeries 
                yField="Revenue" 
                 displayName="Revenue"/>
        </mx:series>
     </mx:ColumnChart>
  </s:Panel>

Here the labels on horizontal axis will be Jan, Feb and Mar. I want to add labels April and May to the horizontal axis dynamically if they are not present in the array collection. Their vertical axis value(in this case revenue) will be 0. I hope the question is clear now.


expenses.addItem({Month:"April"});
expenses.addItem({Month:"May"});

You can just add items to your dataProvider. Is it suitable?

0

精彩评论

暂无评论...
验证码 换一张
取 消