16
Oct
07

Dropping labels in a Flex Chart

In a slightly modified version of a previous example (“Charting in Flex Builder 3 (public beta 1 edition)” — hooray for recycling!), this time we look at removing some of the crowded labels along the horizontal axis by setting the canDropLabels style.

Full code after the jump.

View MXML

<?xml version="1.0"?>
<!-- http://blog.flexexamples.com/2007/10/16/dropping-labels-in-a-flex-chart/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:XML id="quotesXML" source="adbe.xml" format="e4x" />
    <mx:XMLListCollection id="adbe" source="{quotesXML.quote}" />

    <mx:String id="ADBE_YAHOO">http://finance.yahoo.com/q?d=t&s=ADBE</mx:String>

    <mx:ApplicationControlBar dock="true">
        <mx:CheckBox id="checkBox"
                label="canDropLabels:"
                labelPlacement="left" />
    </mx:ApplicationControlBar>

    <mx:LinkButton
            label="ADBE"
            click="navigateToURL(new URLRequest(ADBE_YAHOO))"
            fontSize="14"
            fontWeight="bold" />

    <mx:HLOCChart id="hlocChart"
            showDataTips="true"
            dataProvider="{adbe}"
            width="100%"
            height="100%">

        <!-- vertical axis -->
        <mx:verticalAxis>
            <mx:LinearAxis baseAtZero="false" title="Price" />
        </mx:verticalAxis>

        <!-- horizontal axis -->
        <mx:horizontalAxis>
            <mx:CategoryAxis categoryField="@date" title="Date" />
        </mx:horizontalAxis>

        <!-- horizontal axis renderer -->
        <mx:horizontalAxisRenderer>
            <mx:AxisRenderer canDropLabels="{checkBox.selected}" />
        </mx:horizontalAxisRenderer>

        <!-- series -->
        <mx:series>
            <mx:HLOCSeries id="series1"
                    highField="@high"
                    lowField="@low"
                    openField="@open"
                    closeField="@close"/>
        </mx:series>
    </mx:HLOCChart>

</mx:Application>

View source is enabled in the following example.


6 Responses to “Dropping labels in a Flex Chart”


  1. 1 abul Chowdhury Oct 26th, 2007 at 6:30 am

    I am looking for an example to do a dynamic display in chart - where data will come from MS SQL db via coldfuion - also chart will refresh with newer data set and will refresh it in certain interval. I am very new in flex — I think I am good in CF and SQL.

    Thanks in advance.

  2. 2 rohti Mar 14th, 2008 at 5:00 am

    hi,

    this is really great example ..
    i am keen searcing of this type of example.

    i have one suggestion not related to this example but related to GUI
    ie. the search text color is not properly visible please make it white like other text oolor.

  3. 3 mike Apr 15th, 2008 at 7:14 pm

    hi,

    i dont know if this is the right place to ask some help. Im stuck. i have m source code below. i dont why but i got an error with my chart when i run it. Thanks bud.

    private function date_labelFuncForChart(item:Object, column:CategoryAxis):String
    {

    return dateFormatter.format(item.priceDate );
    }

  4. 4 narendra Bisht May 8th, 2008 at 7:26 pm

    I want to see an example of flex chart which could display project activities in simple manner.
    Narendra Bisht
    High Mountain Biodiversiyty Conservation Project, Bajhnag Nepal

  5. 5 evil-spirit Nov 2nd, 2008 at 7:42 pm

    we can make the x label to years mounths or days! that looks good!

  6. 6 platus Nov 16th, 2008 at 8:56 am

    You’re using a CategoryAxis to display the date. What if you had a date range in hours or minutes inteval, and it’s important to you to show when the DATE suddenly changes?

    for example:

    | | | |
    23:45 23:55 29/3 00:05 00:15

    in this example, flex could decide to drop the “29/3 00:05″ label.
    Is there a way to force him not to drop certain (important) labels?
    (Or maybe some other idea to convery that the day has changed?)

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".




Badge Farm

  • Powered by Redoable 1.2
  • Cornify
  • Feeds burnt by Feedburner
  • Feed