如何在 Flex 折线图的水平轴上显示按年份分组的月份?
基本上我有一个 Flex 折线图,x 轴如下所示:
---|--------|--------|--------|--------|--------|--------|---
November December January February March April May
这很好,但我也想显示月份所属的年份,如下所示:
---|--------|--------|--------|--------|--------|--------|---
November December January February March April May
2010 | 2011
我的数据提供程序是一个 xml 文档,如下所示:
<Chart>
<Month count="1" month="November" year="2010" />
<Month count="5" month="December" year="2010" />
<Month count="0" month="January" year="2011" />
<Month count="10" month="February" year="2011" />
<Month count="3" month="March" year="2011" />
<Month count="9" month="April" year="2011" />
<Month count="3" month="May" year="2011" />
</Chart>
这就是我的 LineChart 控件:
<mx:LineChart
height="100%"
width="100%"
dataProvider="{this._report.Month}">
<mx:backgroundElements>
<mx:GridLines>
<mx:horizontalStroke>
<mx:Stroke color="0x000000" weight="1" />
</mx:horizontalStroke>
</mx:GridLines>
</mx:backgroundElements>
<mx:horizontalAxisRenderers>
<mx:AxisRenderer
axis="{months}"
axisStroke="{axis}"
placement="bottom"
tickLength="5"
tickPlacement="outside"
labelRotation="45">
<mx:tickStroke>{ticks}</mx:tickStroke>
</mx:AxisRenderer>
</mx:horizontalAxisRenderers>
<mx:verticalAxisRenderers>
<mx:AxisRenderer
axis="{countForMonths}"
axisStroke="{axis}"
placement="bottom"
tickLength="5"
tickPlacement="outside"
minorTickPlacement="none">
<mx:tickStroke>{ticks}</mx:tickStroke>
</mx:AxisRenderer>
</mx:verticalAxisRenderers>
<mx:horizontalAxis>
<mx:CategoryAxis id="months" categoryField="@month"/>
</mx:horizontalAxis>
<mx:verticalAxis>
<mx:LinearAxis id="countForMonths" />
</mx:verticalAxis>
<mx:series>
<mx:LineSeries
yField="@count"
displayName="Report"
lineStroke="{myreportstroke}"/>
</mx:series>
</mx:LineChart>
我花了几个小时试图找到一个执行类似操作的示例,但没有成功。 Flex 文档有几个示例,显示 y 轴上的多个轴,但没有显示 x 轴。
我看到其他人提出的其他几个问题想要做类似的事情,但他们中的大多数人从未得到答案,或者答案是查看多个轴的文档 - 我已经完成了。
我发现 此位于 IBM 站点上,用于其 Flex 组件之一。这似乎表明可以按照我想要的方式格式化轴。我只需要有人引导我走向正确的方向。
Basically I have a Flex Line Chart and x-axis looks like this:
---|--------|--------|--------|--------|--------|--------|---
November December January February March April May
This is fine but I also want to show the year that the months belong to, like this:
---|--------|--------|--------|--------|--------|--------|---
November December January February March April May
2010 | 2011
My dataprovider is an xml document that looks like this:
<Chart>
<Month count="1" month="November" year="2010" />
<Month count="5" month="December" year="2010" />
<Month count="0" month="January" year="2011" />
<Month count="10" month="February" year="2011" />
<Month count="3" month="March" year="2011" />
<Month count="9" month="April" year="2011" />
<Month count="3" month="May" year="2011" />
</Chart>
And this is what I have for the LineChart control:
<mx:LineChart
height="100%"
width="100%"
dataProvider="{this._report.Month}">
<mx:backgroundElements>
<mx:GridLines>
<mx:horizontalStroke>
<mx:Stroke color="0x000000" weight="1" />
</mx:horizontalStroke>
</mx:GridLines>
</mx:backgroundElements>
<mx:horizontalAxisRenderers>
<mx:AxisRenderer
axis="{months}"
axisStroke="{axis}"
placement="bottom"
tickLength="5"
tickPlacement="outside"
labelRotation="45">
<mx:tickStroke>{ticks}</mx:tickStroke>
</mx:AxisRenderer>
</mx:horizontalAxisRenderers>
<mx:verticalAxisRenderers>
<mx:AxisRenderer
axis="{countForMonths}"
axisStroke="{axis}"
placement="bottom"
tickLength="5"
tickPlacement="outside"
minorTickPlacement="none">
<mx:tickStroke>{ticks}</mx:tickStroke>
</mx:AxisRenderer>
</mx:verticalAxisRenderers>
<mx:horizontalAxis>
<mx:CategoryAxis id="months" categoryField="@month"/>
</mx:horizontalAxis>
<mx:verticalAxis>
<mx:LinearAxis id="countForMonths" />
</mx:verticalAxis>
<mx:series>
<mx:LineSeries
yField="@count"
displayName="Report"
lineStroke="{myreportstroke}"/>
</mx:series>
</mx:LineChart>
I have spent hours trying to find an example that does something similar with no luck. The Flex documentation has several examples that show multiple axes on the y-axis but none for the x-axis.
I have seen several other questions posted by other people that want to do something similar but most of them never got an answer or the answer was look at the documentation for multiple axes - which I've already done.
I found this on the IBM site for one of their Flex components. This seems to indicate that it is possible to format the axis in the way I want. I just need someone to steer me in the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常有趣的问题。要去调查一下。我的起点将在这里: http://christianyates .com/blog/flex/displaying-multiple-axes-single-series-flex-charts
Very interesting problem. Going to look into it. Starting point for me will be here: http://christianyates.com/blog/flex/displaying-multiple-axes-single-series-flex-charts