动态更新图例 - ActionScript 3

发布于 2024-08-03 11:26:08 字数 619 浏览 5 评论 0原文

我在更新使用动作脚本创建的图例时遇到一些问题。

请阅读以下步骤以了解该问题。

  1. 创建了包含两个数据系列的折线图。
  2. 创造了一个传奇。
  3. 将图表和图例附加到容器。

  4. 有一个更新按钮。单击按钮。

  5. 现在折线图已更新为三个数据系列。
  6. 当我尝试更新图例时,它仍然指向带有两个标签而不是三个标签的初始值。

    当我尝试更新图例时,它仍然指向
  7. 我用来实现的代码(6)

选项(1)

this["containerId"].getChildByName("legendName").dataProvider = LineChart(this[" containerId"].getChildByName("chartName"));

选项 (2)

this["containerId"].getChildByName("legendName").dataProvider = this["containerId"].getChildByName("chartName") as LineChart;

有什么意见吗?

谢谢 杰伊

I have some issues in updating the legends created using action script.

Please read the following steps to understand the issue.

  1. Created a line chart with two data Series.
  2. Created a legend.
  3. Appended chart and legend to a container.

  4. There is an update button. Clicked on the button.

  5. Now the line chart was updated with three data Series.
  6. When i tried to update the legend , it was still pointing to the initial values with two labels instead of three.

  7. The code I used to achieve (6)

option (1)

this["containerId"].getChildByName("legendName").dataProvider = LineChart(this["containerId"].getChildByName("chartName"));

option (2)

this["containerId"].getChildByName("legendName").dataProvider = this["containerId"].getChildByName("chartName") as LineChart;

Any comments?

Thanks
Jay

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

养猫人 2024-08-10 11:26:08

大约一年前,我使用 Flex 图表做了一些繁重的工作,它们可能会成为持续的挫败感来源。事实上,他们的内心非常聪明,这导致他们的行为很难推理。

我注意到的一件事是,有时当您更改数据时,实际上可能需要几帧才能使其通过层次结构。也就是说,即使您在更新系列信息时在同一帧上更新图例上的 dataProvider,您也可能无法绑定到实例的正确版本,因为它会在几帧内发生变化。 (即对Series 的更改是异步的,对dataProvider 的更改是同步的)。

一个快速测试看看这是否是您的问题,只需安装一个黑客计时器即可。将其设置为 100 毫秒左右,然后稍后设置您的 dataProvider ——希望当对 Series 的更改已经达到必要的属性时。另一个想法是使用第二个按钮,一旦您直观地看到新的 Series,就使用该按钮触发图例 dataProvider 的分配。这不是一个生产就绪的解决方案,但它至少可以确定问题的性质。

如果这是您的问题(我怀疑但不确定),那么开始寻找来自所有图表组件的事件。表示新系列已绘制的事件可能来自任何地方,但您最终会找到它。祝你好运。


另外,

var foo:Bar = Bar(obj); // if !(obj is Bar) throw Error

如果您确定 obj 会强制转换为 Bar ,则

var foo:Bar = obj as Bar; // if !(obj is Bar) return null

第一个是最好的,如果不是,则会抛出异常(事实上如果它没有转换为 Bar,则会出现错误)。第二个(as)适用于当 obj 有合理的机会 obj 不会是 Bar 并且不会抛出错误并且将返回 null

由于这种行为,Adobe 建议尽可能使用第一种表单。

About 1 year ago I did some heavy lifting with Flex charts and they can be a constant source of frustration. The fact is they are very clever inside which leads to very difficult to reason about behaviours.

One thing I noticed was that sometimes when you change data, it can actually take a few frames for it to trickle through the hierarchy. That is even if you update the dataProvider on the legend on the same frame as when you update the series information you may not be binding to the correct version of the instance since it will change in a few frames. (i.e. the change to the Series is asynchronous and the change to the dataProvider is synchronous).

One quick test to see if this is your problem is just to put a hack timer in place. Set it for 100ms or so and then set your dataProvider later -- hopefully when the changes to the Series have worked their way to the necessary property. Another idea is to use a second button and once you visually see the new Series use that button to trigger the assignment of the legends dataProvider. That isn't a production ready solution but it will at least determine the nature of the problem.

If it is your problem (which I suspect but am not certain of) then start looking for events that come from all of the chart components. The event that signals the new Series has been drawn may come from anywhere but you'll find it eventually. Good luck.


Also, the difference between:

var foo:Bar = Bar(obj); // if !(obj is Bar) throw Error

and

var foo:Bar = obj as Bar; // if !(obj is Bar) return null

is the first is best if you are certain obj will cast to a Bar and it will throw an exception if it isn't (in fact it would be an error if it didn't cast to a Bar). The second (as) is for when there is a reasonable chance obj won't be a Bar and it won't throw an error and will instead return null.

Because of this behaviour Adobe recommends that the first form be used whenever possible.

硬不硬你别怂 2024-08-10 11:26:08

这是 Flex 的一个主要问题:很难与 AS3 一起使用...最好使用 MXML 并创建绑定...问题应该会消失...

我不完全理解的一件事是,为什么一个child 是另一个的数据提供者,但也许您的应用程序的布局清楚地说明了这一点...通常,数据提供者来自应用程序的数据模型...


编辑:
我认为,绑定是最好的方法......
您应该按如下方式创建一个类:

class Data {
    [Bindable(event="legendChanged")]
    public function get legend():LegendType {/*implementation*/}
    [Bindable(event="chartChanged")]
    public function get chart():ChartType {/*implementation*/}
    public function choseGraph(index:uint):void {
         //update state so the getters for chart and legend will return the right values
         this.dispatchEvent(new Event("legendChanged"));
         this.dispatchEvent(new Event("chartChanged"));
    }    
}

然后将您的视图绑定到它。

this is a major problem with flex: it is very hard to use with AS3 ... better go with MXML and create bindings ... the problem should probably go away ...

a thing i don't fully understand is, why one child is the dataprovider to another, but maybe the layout of your app makes that clear ... usually, dataproviders come from the app's data model ...


edit:
i think, bindings are the best approach ...
you should create a class as follows:

class Data {
    [Bindable(event="legendChanged")]
    public function get legend():LegendType {/*implementation*/}
    [Bindable(event="chartChanged")]
    public function get chart():ChartType {/*implementation*/}
    public function choseGraph(index:uint):void {
         //update state so the getters for chart and legend will return the right values
         this.dispatchEvent(new Event("legendChanged"));
         this.dispatchEvent(new Event("chartChanged"));
    }    
}

and then bind your view to it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文