English 中文(简体)
创造弹性工时轴
原标题:Create Dynamic DateTimeAxis in Flex

我有一张X-轴图,显示时间,Y-轴显示物体的价值。 时间线值为零秒。 我为用户选择时间表提供了途径,用户可以选择一天/周/月/月。 因此,在我的图表中,我想显示选定范围的所有数据点,但希望限制在X-轴上显示的日期标签。 就Ex而言:如果用户选择一个星期,我想在X-轴上向太阳展示。 如果用户选择一天,则希望每3小时贴上标签......

我猜测,如果只有这样,我才有可能根据起始时间(t1)和终点时间(t2)来看待选定的时间范围,我作出决定。 是否在弹性日轴上提供了任何抗体反应器以达到这一目的? 还是就如何开展这项工作的其他想法?

Thanks, Ravi

最佳回答

我在试图将日期与我的意愿相提并论时遇到了许多困难:

我更经常地发现,在专门情况下,如:<编码>extend。 <代码>CategoryAxis。 你们总是能够产生你所关心和使用这些轴心的各种日期。 我不相信这将有利于你的工作,但这是我首先想到的。

这当然需要付出更多的努力,因为你需要定制显示轴心,以便像日期或时间一样,但我认为它有助于处理习俗。

问题回答

奥凯找到了解决这一问题的办法。 类似于上文提及的“@fotomut”。 除重写假法外,我从Axis类复制了所有代码。 这就是标签产生的地方。 我在此采用更新方法,可能不是一个完美的解决办法。

但我在此面临一个问题。 出于某种原因,图表和标签倾向于右侧。 我无法画出一个图象,把我的习惯性轴比同提供的各类轴体相比较,以更好地解释这一点,因为我仅限于不上任何档案。 我正试图解决这一问题,但还没有找到解决办法。

if (!_labelSet)
{

    //I do not need label for each item in my dataprovider.
    //Hence creating a  categoryValues  array with limited labels.
    var chartDP:ArrayCollection = this.dataProvider as ArrayCollection;
    var axisLabels:Array /* of AxisLabel */ = [];
    var labelsArr:Array = [];
    var categoryItems:Array = [];
    var dataMap:Object = {};
    _catMap = {};
    _categoryValues = [];
    _labelsMatchToCategoryValuesByIndex = [];

    if(chartDP.length != 0) {

        for(var indx:int=0; indx<chartDP.length; indx++){

            // Add each item to the map.
            //This is mandatory as it s being used internally to draw the Y-value
            _catMap[chartDP.getItemAt(indx).timeStamp.toString()] = indx;
        }

        var firstItem:Object = chartDP.getItemAt(0);
        var lastItem:Object = chartDP.getItemAt(chartDP.length - 1);
        var incrCounter:int; 

        var timeDiffInMillis:Number = (lastItem.timeStamp) - (firstItem.timeStamp);
        var arrIndx:int=0;
        if(timeDiffInMillis <= MILLISECONDS_IN_HOUR){
            LIMIT_LABEL_CNT = 12;
            INT_LBL_UNITS = "MINUTES";
        }else if(timeDiffInMillis > MILLISECONDS_IN_HOUR && timeDiffInMillis <= MILLISECONDS_IN_DAY){
            LIMIT_LABEL_CNT = 12;
            INT_LBL_UNITS = "HOURS";
        }else if(timeDiffInMillis > MILLISECONDS_IN_DAY && timeDiffInMillis <= MILLISECONDS_IN_WEEK){
            LIMIT_LABEL_CNT = 7;
            INT_LBL_UNITS = "DAYS";
        }else if(timeDiffInMillis > MILLISECONDS_IN_WEEK && timeDiffInMillis <= MILLISECONDS_IN_MONTH){
            LIMIT_LABEL_CNT = 4;
            INT_LBL_UNITS = "WEEKS";
        }else if(timeDiffInMillis > MILLISECONDS_IN_MONTH && timeDiffInMillis <= MILLISECONDS_IN_YEAR) {
            LIMIT_LABEL_CNT = 12;
            INT_LBL_UNITS = "MONTHS"
        }

        if(chartDP.length <= LIMIT_LABEL_CNT)
            incrCounter = 1;
        else
            incrCounter = chartDP.length/LIMIT_LABEL_CNT;
        var i:int=0;
        for(i=0,arrIndx=0; i<chartDP.length; i=i+incrCounter){

            arrIndx = i;
            _categoryValues[arrIndx] = chartDP.getItemAt(i).timeStamp; 
            dataMap[arrIndx] = chartDP.getItemAt(i);

            //There is a very good chance for the incrCounter to omit
            //the last items in the DataProvider.
            if((chartDP.length-i) <= incrCounter){
                arrIndx=arrIndx+incrCounter;
                _categoryValues[arrIndx] = chartDP.getItemAt(chartDP.length-1).timeStamp; 
                dataMap[arrIndx] = chartDP.getItemAt(chartDP.length-1);
            }
        }

        var min:Number = -_padding;
        var max:Number = _categoryValues.length - 1 + _padding;
        var alen:Number = max - min;
        var label:AxisLabel;

        var n:int = _categoryValues.length;
        if (_labelFunction != null)
        {
            var previousValue:Object = null;
            for (i=0; i<n; i++)
            {
                if (_categoryValues[i] == null)
                    continue;

                if(previousValue != null && _categoryValues[i] != null){
                    if(previousValue == _categoryValues[i])
                        continue;
                }
                label = new AxisLabel((i - min) / alen, _categoryValues[i],
                    timeLblFormatFunction(_categoryValues[i], previousValue,
                        this, dataMap[i]));
                _labelsMatchToCategoryValuesByIndex[i] = label;
                axisLabels.push(label);

                previousValue = _categoryValues[i];
            }
        }
        else
        {
            for (i = 0; i < n; i++)
            {
                if (!_categoryValues[i])
                    continue;

                label = new AxisLabel((i - min) / alen, _categoryValues[i],
                    _categoryValues[i].toString());
                _labelsMatchToCategoryValuesByIndex[i] = label;
                axisLabels.push(label);
            }               
        }
    }

    _labelSet = new AxisLabelSet();
    _labelSet.labels = axisLabels;
    _labelSet.accurate = true;
    _labelSet.minorTicks = minorTicks;
    _labelSet.ticks = generateTicks();          
}




相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签