在 Flex 图表上绘图

发布于 2024-11-27 17:24:55 字数 269 浏览 1 评论 0原文

我在 Flex 中创建了一个折线图,它的工作原理与预期一致。现在,我想为背景添加阴影以获取特定信息。例如,此图表 - http://research.stlouisfed.org/fred2/ graph/?id=TOTALSL,TOTALNS, - 显示经济衰退的阴影背景。我如何在 Flex 折线图中模仿这种阴影?

谢谢

I've created a line chart in flex and it works like expected. Now, I would like to add shading to the background for specific information. For example, this chart - http://research.stlouisfed.org/fred2/graph/?id=TOTALSL,TOTALNS, - shows a shaded background for recessions. How would I mimic this shading in a Flex linechart?

Thanks

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

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

发布评论

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

评论(2

撕心裂肺的伤痛 2024-12-04 17:24:55

您可以使用绘图 api 在图表的背景中绘制它。

编辑:

我不知道网络上有任何代码示例,我只在生产代码中完成了它(又名我无法分享它,抱歉:()
您将需要创建一个容器并将其放入图表中。

<mx:backgroundElements>

您应该将 x 轴的最小值和最大值可能作为单独的属性以及描述何时显示突出显示部分的数据提供程序传递到该容器中。您可能必须根据传递到图表中的数据提供程序来计算最小值和最大值。

如果您只想显示突出显示的区域,您只需使用绘图 API 并根据数据提供者的最小值、最大值、容器宽度以及数据点(开始值和结束值)计算 X 轴上的放置位置。它在你的 updateDisplayList 中看起来像这样:

// code is not tested but a good start

var shadeStartX:Number = (max-min)/startPoint; 
var shadeEndX:Number = (max-min)/endPoint;
var shadeWidth:Number = shadeEndX - shadeStartX;

...

this.graphics.drawRect(shadeStartX, 0, shadeWidth, unscaledHeight);

但如果你想要像悬停状态这样的东西和所有这些优点,我建议创建一个显示对象,你将宽度传入并将其添加到计算的 x 轴处的容器中将其设置为。

You could draw it in the background of the chart using the drawing api.

edit:

I dont know of any code examples on the web, I've only done it in production code (aka I cant share it, sorry :( )
you will want to create a container and put it into the charts

<mx:backgroundElements>

You should pass into this container the min and max for the x-axis probably as separate properties and a dataprovider that describes when to show a highlighted section. You might have to compute the min and max based on the dataprovider you pass into the chart.

If you just want to show the highlighted area you will just use the drawing api and compute where to put on the x-axis based on your min, max, width of container, and data point (start and end values) from your dataprovider. It will look something like this in your updateDisplayList:

// code is not tested but a good start

var shadeStartX:Number = (max-min)/startPoint; 
var shadeEndX:Number = (max-min)/endPoint;
var shadeWidth:Number = shadeEndX - shadeStartX;

...

this.graphics.drawRect(shadeStartX, 0, shadeWidth, unscaledHeight);

but if you want to have things like hover states and all that goodness I would suggest creating a display object that you pass the width in and adding that to the container at the computed x-axis to set it at.

娇妻 2024-12-04 17:24:55

嗨,我觉得自己画东西不是正确的方法。
理想情况下,您应该在 LineChart 中使用 PlotSeries,并为系列中的每个元素创建一个自定义项目渲染器。

PlotSeries 允许您提供自己的自定义图像/对象以在图表中的特定日期/点绘制。

http://help.adobe.com /en_US/FlashPlatform/reference/actionscript/3/mx/charts/series/PlotSeries.html

http://livedocs.adobe.com/flex/3/html /help.html?content=charts_types_10.html

所有示例都显示具有较小对象的plotSeries,但您可以创建一个垂直覆盖图表并具有恒定宽度的对象。

Hi I feel that drawing something yourself is not the right way to go.
You should ideally use a PlotSeries inside the LineChart, and create a custom item renderer for each element in the series.

PlotSeries allows you to give your own custom image/object to draw at a specific date/point in the chart.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/charts/series/PlotSeries.html

http://livedocs.adobe.com/flex/3/html/help.html?content=charts_types_10.html

All the examples show the plotSeries with smaller objects but you can create an object which covers the chart vertically and has a constant width.

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