3 Replies Latest reply on Sep 10, 2007 3:54 PM by dfxoreilly

    BarChart with single negative value

    dfxoreilly
      mxml code is as follows:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      creationComplete="myData.send()" horizontalAlign="left" verticalAlign="top">

      <mx:HTTPService id="myData" url="negative.xml" />
      <mx:VBox >
      <mx:BarChart id="bc1"
      dataProvider="{myData.lastResult.distribution.point}" showDataTips="true" >
      <mx:series>
      <mx:BarSeries xField="y" />
      </mx:series>
      <mx:verticalAxis>
      <mx:CategoryAxis categoryField="x" />
      </mx:verticalAxis>
      </mx:BarChart>

      </mx:VBox>
      </mx:Application>

      The data file, negative.xml, is as follows:

      <distribution>
      <point> <x> A </x> <y> -200 </y> </point>
      </distribution>

      As it stands, nothing appears in the chart.
      If you change the -200 to 200, it works! Rather bizarre!

      Anyone have a work around?
        • 1. Re: BarChart with single negative value
          Kurt Mossman Adobe Employee

          I subclassed LinearAxis and this get's the correct minimum value.

          --------- modified example ---------

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:local="*" xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
          creationComplete="myData.send()" horizontalAlign="left" verticalAlign="top">

          <mx:HTTPService id="myData" url="negative.xml" />
          <mx:VBox >
          <mx:BarChart id="bc1"
          dataProvider="{myData.lastResult.distribution.point}" showDataTips="true" >
          <mx:series>
          <mx:BarSeries xField="y" />
          </mx:series>

          <mx:horizontalAxis>
          <local:MyLinearAxis />
          </mx:horizontalAxis>
          <mx:verticalAxis>
          <mx:CategoryAxis categoryField="x" />
          </mx:verticalAxis>
          </mx:BarChart>

          </mx:VBox>

          </mx:Application>


          ----- MyLinearAxis.as -------------------

          package
          {
          import mx.charts.LinearAxis;

          public class MyLinearAxis extends LinearAxis
          {

          public function MyLinearAxis()
          {
          super();
          }

          override protected function adjustMinMax(minValue:Number,
          maxValue:Number):void
          {

          super.adjustMinMax(minValue,maxValue);

          if(dataDescriptions.length){
          computedMinimum = this.dataDescriptions[0].min;
          }

          }

          }
          }

          I think this should do the trick.

          -Kurt
          • 2. Re: BarChart with single negative value
            Kurt Mossman Adobe Employee

            Minor change to this... we only want to do this if we are working with negative numbers not positive. Strange things happen to the label without this version.


            package
            {
            import mx.charts.LinearAxis;

            public class MyLinearAxis extends LinearAxis
            {

            public function MyLinearAxis()
            {
            super();
            }

            override protected function adjustMinMax(minValue:Number,
            maxValue:Number):void
            {

            super.adjustMinMax(minValue,maxValue);

            if(dataDescriptions.length && (this.dataDescriptions[0].min < 0)){
            computedMinimum = this.dataDescriptions[0].min;
            }

            }

            }
            }
            • 3. Re: BarChart with single negative value
              dfxoreilly Level 1
              Kurt, thanks for the override. Also found another possible approach involving adding an extra series ( values are negatives of the desired series ) with alpha set equal 0 so that it is invisible, and barWidthRatio = "1.3". Alignment with labels is awful, but it was already ugly upon resize.