Hi All,

 Here I'm pasting my sample code to export a Pie Chart.


<?xml version="1.0"?>
<!-- Simple example to demonstrate the PieChart control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
xmlns:MyComps="mx.charts.*">

    <mx:Script>
        <![CDATA[

        import mx.collections.ArrayCollection;
        import mx.core.UIComponent;
        import mx.graphics.codec.*;
        import mx.printing.*;
        import flash.events.*;
        import flash.utils.Timer;

        [Bindable]
        private var medalsAC:ArrayCollection = new ArrayCollection( [
            { Country: "USA", Gold: 35, Silver:39, Bronze: 29 },
            { Country: "China", Gold: 32, Silver:17, Bronze: 14 },
            { Country: "Russia", Gold: 27, Silver:27, Bronze: 38 } ]);

        var request:URLRequest;

        private function displayGold(data:Object, field:String,
index:Number, percentValue:Number):String {
            var temp:String= (" " + percentValue).substr(0,6);
            return data.Country + ": " + '\n' + "Total Gold: " +
data.Gold + '\n' + temp + "%";
        }

        private function export_itemClick(event:MouseEvent):void {
            var ba:ByteArray = getByteArrayData(chart);
            trace("PieChart in ByteArray: \n" + ba);
            request = new URLRequest("save.php");
            request.method = URLRequestMethod.POST;
            sendData();
        }

        private function sendData():void {
            // code to handle the URL variable data to the server side and
helps in writing in to a file
        }

        private function getByteArrayData( target:UIComponent ):ByteArray {
            trace("Height: " + target.height + " Width: " + target.width);
            var bd:BitmapData = new BitmapData(target.height, target.width);
            bd.draw(target, new Matrix());

            var e:JPEGEncoder = new JPEGEncoder();
            return e.encode(bd);
        }

        ]]>
    </mx:Script>

    <mx:Panel id="panel1" title="Olympics 2004 Medals Tally Panel"
height="80%" width="70%">

        <mx:PieChart id="chart" height="50%" width="50%"
paddingRight="5" paddingLeft="5"
            showDataTips="true" dataProvider="{medalsAC}" >

            <mx:series>
                <mx:PieSeries labelPosition="callout" field="Gold"
labelFunction="displayGold">
                    <mx:calloutStroke>
                        <mx:Stroke weight="0" color="0x888888"
alpha="1.0"/>
                    </mx:calloutStroke>
                    <mx:radialStroke>
                        <mx:Stroke weight="0" color="#FFFFFF"
alpha="0.20"/>
                    </mx:radialStroke>
                    <mx:stroke>
                        <mx:Stroke color="0" alpha="0.20" weight="2"/>
                    </mx:stroke>
                </mx:PieSeries>
            </mx:series>
        </mx:PieChart>

        <mx:Button id="export" label="Export PieChart as Image"
textAlign="center"
            click="export_itemClick(event);"/>

    </mx:Panel>

</mx:Application>

 Byte array conversion is not proper. I tried to trace the bytearray
printed in to the flashlog.txt. It looks like this   "A¿A~A¿A"

 I tried it for many types of charts etc. But what ever bytearray it
wrote into the file is same.
What ever data it wrote in to the file is not fine and when I tried to
open the image ..its saying "Cant read file header" ..., "Unknown
fileformat".

 I am able to write some text in to file. Its working fine. but
exporting the image is not working.

 Can any one tell me where am I lost.

 Help me & guide me.

Thanks,
Anil


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---

  • ... Anil
    • ... Anil
    • ... Anil
      • ... subeesh a
        • ... umair
          • ... Satish பேர கேட்டா சும்மா அதுருதில
          • ... Anil
          • ... Anil
        • ... Anil

Reply via email to