0

我有一个与图表有关的问题。

我有 1000 多列的柱形图,上面有滚动条。现在我想将它作为图像保存到我的 Disktop 或任何不滚动的位置。

我从其中一个链接下载的 ScrollableAxisRenderer 类请在下面找到它: - http://www.connectedpixel.com/blog/scrollingcharts

示例柱形图示例:-

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               creationComplete="init();" xmlns:charts="com.connectedpixel.charts.*">
    <fx:Declarations>
        <fx:XML xmlns="" id="myData">
            <items>
                <item year="1960" rain="92" />
                <item year="1961" rain="192" />
                <item year="1962" rain="32" />
                <item year="1963" rain="52" />
                <item year="1964" rain="112" />
                <item year="1965" rain="52" />
                <item year="1966" rain="88" />
                <item year="1967" rain="52" />
                <item year="1968" rain="66" />
                <item year="1969" rain="39" />
                <item year="1970" rain="192" />
                <item year="1971" rain="182" />
                <item year="1972" rain="177" />
                <item year="1973" rain="179" />
                <item year="1974" rain="198" />
                <item year="1975" rain="207" />
                <item year="1976" rain="388" />
                <item year="1977" rain="372" />
                <item year="1978" rain="352" />
            </items>
        </fx:XML>

        <s:XMLListCollection id="rainData" source="{myData.children()}" />

    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.graphics.ImageSnapshot;
            import mx.graphics.codec.PNGEncoder;

            protected function initCreationComp():void
            {
                var image:ImageSnapshot = ImageSnapshot.captureImage(myChart,300,new PNGEncoder(),true);
                var file:FileReference = new FileReference();
                var chartName:String = "myChart"+count+".png";
                file.save(image.data, chartName);
            }

        ]]>
    </fx:Script>

    <mx:VBox width="100%" height="100%" x="50" y="50">
        <s:Button label="Download Image" click="initCreationComp()"/>

        <mx:ColumnChart id="myChart" name="myChart"  
                        width="80%" height="80%" 
                        dataProvider="{myData.children()}" 
                        showDataTips="true" maxColumnWidth="35">
            <mx:horizontalAxis>
                <mx:CategoryAxis id="yearAxis"  categoryField="@year"   />
            </mx:horizontalAxis>

            <mx:series>
                <mx:ColumnSeries xField="@year"  yField="@rain" displayName="Rain" />
            </mx:series>

            <mx:horizontalAxisRenderers>
                <charts:ScrollableAxisRenderer id="scrollAxisRenderer" axis="{yearAxis}" tickPlacement="none"   
                                               placement="bottom" labelGap="3" maxVisibleColumns="4"/>
            </mx:horizontalAxisRenderers>

        </mx:ColumnChart>
    </mx:VBox>
</s:Application>

提前致谢....

4

1 回答 1

0

将图表放在将显示滚动条而不是图表的容器中:

<mx:VBox width="100%" height="100%" x="50" y="50">
    <s:Button label="Download Image" click="initCreationComp()"/>
    <mx:VBox width="80%" height="80%"
             minWidth="100" minHeight="100">
        <mx:ColumnChart id="myChart" name="myChart"  
                        dataProvider="{myData.children()}" 
                        showDataTips="true" maxColumnWidth="35">
         <!-- etc -->
        </mx:ColumnChart>
    </mx:VBox>
</mx:VBox>
于 2012-05-11T06:40:59.833 回答