如何在 Flex 折线图的水平轴上显示按年份分组的月份?

发布于 2024-09-30 09:52:40 字数 3022 浏览 1 评论 0原文

基本上我有一个 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 技术交流群。

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

发布评论

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

评论(1

柒七 2024-10-07 09:52:40

非常有趣的问题。要去调查一下。我的起点将在这里: 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

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