Specify an offset used when adding a data child to the canvas for the labels with an HSlider control. : Slider « Components « Flex






Specify an offset used when adding a data child to the canvas for the labels with an HSlider control.

Specify an offset used when adding a data child to the canvas for the labels with an HSlider control.
           

<!--
Code from Flex 4 Documentation "Using Adobe Flex 4".

This user guide is licensed for use under the terms of the Creative Commons Attribution 
Non-Commercial 3.0 License. 

This License allows users to copy, distribute, and transmit the user guide for noncommercial 
purposes only so long as 
  (1) proper attribution to Adobe is given as the owner of the user guide; and 
  (2) any reuse or distribution of the user guide contains a notice that use of the user guide is governed by these terms. 
The best way to provide notice is to include the following link. 
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/

-->


    <!-- charts/AddLabelsWithOffsetLines.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark"
    height="600">

    <s:layout>
        <s:VerticalLayout />
    </s:layout>
    <fx:Script> 
        import mx.charts.series.items.ColumnSeriesItem; 
        import mx.charts.ChartItem; 
        import mx.charts.chartClasses.CartesianCanvasValue; 
        private function connectTwoPoints(month1:String,value1:Number,month2:String,value2:Number):void { 
            canvas.clear(); 
            canvas.lineStyle(4,0xCCCCCC,.75,true,LineScaleMode.NORMAL,CapsStyle.ROUND,JointStyle.MITER,2); 
            canvas.moveTo(month1, value1); 
            canvas.lineTo(month2, value2); 
            l1.text = "Month: " + month1; 
            l2.text = "Profit: " + value1; 
            l3.text = "Month: " + month2; 
            l4.text = "Profit: " + value2; 
            chartHasLine = true; 
        } 
        private var s1:String = new String(); 
        private var s2:String = new String(); 
        private var v1:Number = new Number(); 
        private var v2:Number = new Number(); 
        // Set this to true initially so that the chart doesn't 
        // draw a line when the first item is clicked. 
        private var chartHasLine:Boolean = true; 

  
    import mx.collections.ArrayCollection;
    [Bindable]
    public var expenses:ArrayCollection = new ArrayCollection([
      {month:"Jan", profit:20, expenses:15, amount:145},
      {month:"Feb", profit:1, expenses:2, amount:60},
      {month:"Mar", profit:15, expenses:5, amount:3}
      ]);
        private function handleChange(event:Event):void { 
            var sci:ColumnSeriesItem =ColumnSeriesItem(myChart.selectedChartItem); 
            if (chartHasLine) { 
                canvas.clear(); 
                s1 = sci.item.month; 
                v1 = sci.item.profit; 
                addLabelsToColumn(s1,v1); 
                chartHasLine = false; 
            } else { 
                s2 = sci.item.month; 
                v2 = sci.item.profit; 
                addLabelsToColumn(s2,v2); 
                connectTwoPoints(s1, v1, s2, v2); 
            } 
        } 
        [Bindable] 
        public var labelOffset:Number = 0; 
        [Bindable] 
        public var columnLabel:Label; 
        private function addLabelsToColumn(s:String, n:Number):void { 
            columnLabel = new Label(); 
            columnLabel.setStyle("fontWeight", "bold"); 
            columnLabel.setStyle("color", "0x660000"); 
            columnLabel.text = s + ": " + "$" + n; 
            // Use the CartesianCanvasValue constructor to specify 
            // an offset for data coordinates. 
            canvas.addDataChild(columnLabel,new CartesianCanvasValue(s, labelOffset),new CartesianCanvasValue(n, labelOffset)); 
        } 
      </fx:Script>
    <s:Panel title="Column Chart">
        <s:layout>
            <s:VerticalLayout />
        </s:layout>
        <mx:ColumnChart id="myChart" dataProvider="{expenses}"
            selectionMode="single" change="handleChange(event)">
            <mx:annotationElements>
                <mx:CartesianDataCanvas id="canvas"
                    includeInRanges="true" />
            </mx:annotationElements>
            <mx:horizontalAxis>
                <mx:CategoryAxis categoryField="month" />
            </mx:horizontalAxis>
            <mx:series>
                <mx:ColumnSeries id="series1" xField="month" yField="profit"
                    displayName="Profit" selectable="true" />
            </mx:series>
        </mx:ColumnChart>
        <mx:Legend dataProvider="{myChart}" />
        <s:Button id="b1" label="Connect Two Points"
            click="connectTwoPoints('Jan', 2000, 'Mar', 1500);" />
        <s:HGroup>
            <s:VGroup>
                <s:Label text="First Item" />
                <s:Label id="l1" />
                <s:Label id="l2" />
            </s:VGroup>
            <s:VGroup>
                <s:Label text="Second Item" />
                <s:Label id="l3" />
                <s:Label id="l4" />
            </s:VGroup>
        </s:HGroup>
        <mx:HSlider id="hSlider" minimum="-50" maximum="50" value="0"
            dataTipPlacement="top" tickColor="black" snapInterval="1"
            tickInterval="10" labels="['-50','0','50']" allowTrackClick="true"
            liveDragging="true" change="labelOffset=hSlider.value" />
    </s:Panel>
</s:Application>

   
    
    
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Formatting data tips in a SliderFormatting data tips in a Slider
2.Set snap interval value to 1 for horizontal sliderSet snap interval value to 1 for horizontal slider
3.Set tick interval value for horizontal sliderSet tick interval value for horizontal slider
4.Set value for horizontal sliderSet value for horizontal slider
5.Set minimum value to 1 for horizontal sliderSet minimum value to 1 for horizontal slider
6.Set Horizontal slider to live draggingSet Horizontal slider to live dragging
7.Use HSlider to choose valueUse HSlider to choose value
8.Use VSlider to choose valueUse VSlider to choose value
9.Two thumbs with thumbCount = 2Two thumbs with thumbCount = 2
10.Use a change event to show slider value in a TextArea controlUse a change event to show slider value in a TextArea control
11.Use slider controls to adjust the effect's propertiesUse slider controls to adjust the effect's properties
12.Call setThumbValueAt() method of HSlider to change the slider valueCall setThumbValueAt() method of HSlider to change the slider value
13.Horizontal slider Label settingsHorizontal slider Label settings
14.HSlider, snap and tick intervalHSlider, snap and tick interval
15.VSlider maximum, snap and tick intervalVSlider maximum, snap and tick interval
16.Bind slider value to a Text controlBind slider value to a Text control
17.change event for HSliderchange event for HSlider
18.Slider values property is a two-element array that contains the current value of the thumbsSlider values property is a two-element array that contains the current value of the thumbs
19.Get thumb index for two-thumb sliderGet thumb index for two-thumb slider
20.Use Slider to control the image width, height and alphaUse Slider to control the image width, height and alpha
21.Bind Slider value to a LabelBind Slider value to a Label
22.Set minimum, maximum, tickInterval, snapInterval and Labels for SliderSet minimum, maximum, tickInterval, snapInterval and Labels for Slider
23.Rotating Fonts With SliderRotating Fonts With Slider
24.change width with sliderchange width with slider
25.Use Slider to control the width and height of ConstraintColumnUse Slider to control the width and height of ConstraintColumn
26.Use Slider to control the background color for a BoxUse Slider to control the background color for a Box
27.Set Slider tip functionSet Slider tip function
28.Show a horizontal slider and a vertical slider with different properties set.Show a horizontal slider and a vertical slider with different properties set.
29.HSlider BindingHSlider Binding
30.HSlider EventHSlider Event
31.HSlider Data TipHSlider Data Tip
32.Set alpha of DisplayObject when you move the sliderSet alpha of DisplayObject when you move the slider
33.Use Slider to change vertical Scroll PositionUse Slider to change vertical Scroll Position
34.Use dataTipFormatFunction to format the data tip textUse dataTipFormatFunction to format the data tip text
35.Invoke adjustThumb() method when the user clicks the buttonInvoke adjustThumb() method when the user clicks the button
36.Bind Panel width to HSliderBind Panel width to HSlider