Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a method to calculate and set the interval of a chart
    primarykey
    data
    text
    <p>I am learning flex. And I need your help, I want to create a method to calculate the interval value of the vertical axis depending on the values of the "dataProvider".</p> <pre><code> &lt;mx:verticalAxis&gt; &lt;mx:LinearAxis labelFunction="usageColumnSerieLabelFn" interval="0.0001"/&gt; &lt;/mx:verticalAxis&gt; </code></pre> <p>Like you see, in that piece of code, I am hardcoding the interval. like I said, I want your help in order to create a new method to calculate and set this value.</p> <p>I believe, If we took the greater value in the "dataProvider" and then set this value (greater Value + 0.1) to the interval. Will do the trick. But I dont know how to set the properties outside the mx:LinearAxis component.</p> <p>I made this example, please if you have time, please give me a hand.</p> <p>Regards</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;!-- charts/BasicColumn.mxml --&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt; &lt;mx:Script&gt;&lt;![CDATA[ import mx.collections.ArrayCollection; import flash.external.ExternalInterface; import mx.charts.HitData; import mx.formatters.SwitchSymbolFormatter; import mx.charts.series.items.LineSeriesItem; import mx.charts.HitData; import mx.formatters.NumberFormatter; import mx.core.UIComponent; import mx.effects.easing.Bounce; import mx.managers.PopUpManager; private var decimalFormatter:NumberFormatter = new NumberFormatter(); [Bindable] public var expenses:ArrayCollection = new ArrayCollection([ {hour:"00", Expenses:0.0}, {hour:"01", Expenses:0.0}, {hour:"02", Expenses:0.0}, {hour:"03", Expenses:0.0}, {hour:"04", Expenses:0.0}, {hour:"05", Expenses:0.0}, {hour:"06", Expenses:0.0}, {hour:"07", Expenses:0.0}, {hour:"08", Expenses:0.0}, {hour:"09", Expenses:0.0}, {hour:"10", Expenses:0.00009}, {hour:"11", Expenses:0.00009}, {hour:"12", Expenses:0.0}, {hour:"13", Expenses:0.0}, {hour:"14", Expenses:0.0}, {hour:"15", Expenses:0.0}, {hour:"16", Expenses:0.0}, {hour:"17", Expenses:0.0}, {hour:"18", Expenses:0.0}, {hour:"19", Expenses:0.0}, {hour:"20", Expenses:0.0}, {hour:"21", Expenses:0.0}, {hour:"22", Expenses:0.0}, {hour:"23", Expenses:0.00009} ]); private function customDataTipFunc(item:HitData):String{ decimalFormatter.precision = 4; var dataTip:String = ""; dataTip += "&lt;B&gt;kWh&lt;/B&gt;\n"; dataTip += item.item.hour + "\n"; if (item.item.Expenses == 0) { dataTip += decimalFormatter.format(item.item.Expenses).toString() + " kWh"; } else { if(item.item.Expenses &lt; 0.0001) { dataTip += "&amp;lt;0.0001 kWh"; } else { dataTip += decimalFormatter.format(item.item.Expenses).toString() + " kWh"; } } return dataTip; } public function axisLabelFn(cat:Object,pcat:Object,ax:LinearAxis):String{ var nf1:NumberFormatter = new NumberFormatter(); nf1.useThousandsSeparator = true; nf1.precision = 4; var tempNumber:Number = Number(cat.toString()); var out:String = "" if (tempNumber == 0) { out = nf1.format(cat) + " kWh"; }else { if (tempNumber &lt; 0.0001) { out = "&amp;lt;" + nf1.format(cat) + " kWh"; } else { out = nf1.format(cat) + " kWh"; } } //return nf1.format(cat) + " kWh"; return out; } ]]&gt;&lt;/mx:Script&gt; &lt;mx:Panel title="Column Chart Kwh" width="1200"&gt; &lt;mx:ColumnChart id="myChart" showDataTips="true" height="100%" width="100%" dataProvider="{expenses}" minHeight="150" dataTipFunction="customDataTipFunc"&gt; &lt;mx:horizontalAxis&gt; &lt;mx:CategoryAxis dataProvider="{expenses}" categoryField="hour" /&gt; &lt;/mx:horizontalAxis&gt; &lt;mx:verticalAxis&gt; &lt;mx:LinearAxis labelFunction="axisLabelFn" interval="0.0001"/&gt; &lt;/mx:verticalAxis&gt; &lt;mx:series&gt; &lt;mx:ColumnSeries xField="hour" yField="Expenses" displayName="Kwh" /&gt; &lt;/mx:series&gt; &lt;/mx:ColumnChart&gt; &lt;mx:Legend dataProvider="{myChart}"/&gt; &lt;/mx:Panel&gt; &lt;/mx:Application&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload