动态更新图例 - ActionScript 3
我在更新使用动作脚本创建的图例时遇到一些问题。
请阅读以下步骤以了解该问题。
- 创建了包含两个数据系列的折线图。
- 创造了一个传奇。
将图表和图例附加到容器。
有一个更新按钮。单击按钮。
- 现在折线图已更新为三个数据系列。
当我尝试更新图例时,它仍然指向带有两个标签而不是三个标签的初始值。
当我尝试更新图例时,它仍然指向我用来实现的代码(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.
- Created a line chart with two data Series.
- Created a legend.
Appended chart and legend to a container.
There is an update button. Clicked on the button.
- Now the line chart was updated with three data Series.
When i tried to update the legend , it was still pointing to the initial values with two labels instead of three.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大约一年前,我使用 Flex 图表做了一些繁重的工作,它们可能会成为持续的挫败感来源。事实上,他们的内心非常聪明,这导致他们的行为很难推理。
我注意到的一件事是,有时当您更改数据时,实际上可能需要几帧才能使其通过层次结构。也就是说,即使您在更新系列信息时在同一帧上更新图例上的
dataProvider
,您也可能无法绑定到实例的正确版本,因为它会在几帧内发生变化。 (即对Series
的更改是异步的,对dataProvider
的更改是同步的)。一个快速测试看看这是否是您的问题,只需安装一个黑客计时器即可。将其设置为 100 毫秒左右,然后稍后设置您的
dataProvider
——希望当对Series
的更改已经达到必要的属性时。另一个想法是使用第二个按钮,一旦您直观地看到新的Series
,就使用该按钮触发图例dataProvider
的分配。这不是一个生产就绪的解决方案,但它至少可以确定问题的性质。如果这是您的问题(我怀疑但不确定),那么开始寻找来自所有图表组件的事件。表示新
系列
已绘制的事件可能来自任何地方,但您最终会找到它。祝你好运。另外,
如果您确定 obj 会强制转换为 Bar ,则
第一个是最好的,如果不是,则会抛出异常(事实上如果它没有转换为
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 theSeries
is asynchronous and the change to thedataProvider
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 theSeries
have worked their way to the necessary property. Another idea is to use a second button and once you visually see the newSeries
use that button to trigger the assignment of the legendsdataProvider
. 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:
and
is the first is best if you are certain
obj
will cast to aBar
and it will throw an exception if it isn't (in fact it would be an error if it didn't cast to aBar
). The second (as
) is for when there is a reasonable chanceobj
won't be aBar
and it won't throw an error and will instead returnnull
.Because of this behaviour Adobe recommends that the first form be used whenever possible.
这是 Flex 的一个主要问题:很难与 AS3 一起使用...最好使用 MXML 并创建绑定...问题应该会消失...
我不完全理解的一件事是,为什么一个child 是另一个的数据提供者,但也许您的应用程序的布局清楚地说明了这一点...通常,数据提供者来自应用程序的数据模型...
编辑:
我认为,绑定是最好的方法......
您应该按如下方式创建一个类:
然后将您的视图绑定到它。
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:
and then bind your view to it.