1 Reply Latest reply on Mar 13, 2008 10:22 PM by rohitmarathe

    chart to image

    larcelarcen
      hi,
      is there a way to convert chart to image, i am using php in server side.
      thanks
        • 1. Re: chart to image
          rohitmarathe
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Script>
          <![CDATA[
          import mx.collections.ArrayCollection;
          import mx.core.UIComponent;

          private function getBitmapData( target : UIComponent ) : BitmapData
          {
          var bd : BitmapData = new BitmapData( target.width, target.height );
          var m : Matrix = new Matrix();
          bd.draw( target, m );
          img1.source = new Bitmap(bd);
          img1.source
          return bd;
          }
          ]]>
          </mx:Script>
          <mx:Script>
          <![CDATA[
          [Bindable]
          private var arrSalesData:ArrayCollection = new ArrayCollection([
          {Year:"2000", Sales:200000,Profit:20000},
          {Year:"2004", Sales:10000000,Profit:4000000},
          {Year:"2007", Sales:20000000,Profit:7500000}
          ]);
          ]]>
          </mx:Script>
          <mx:Panel x="41" y="20" width="674" height="356" layout="absolute" title="Sales Vs Profit">
          <mx:BarChart x="0" y="0" id="BarChartSales" width="100%" height="281" dataProvider="{arrSalesData}" showDataTips="true">
          <mx:verticalAxis>
          <mx:CategoryAxis categoryField="Year"/>
          </mx:verticalAxis>
          <mx:series>
          <mx:BarSeries displayName="Sales" xField="Sales" yField="Year" />
          <mx:BarSeries displayName="Profit" xField="Profit" yField="Year" />
          </mx:series>
          </mx:BarChart>
          <mx:Legend dataProvider="{BarChartSales}" x="0" y="280" height="36"/>
          <mx:Button x="543" y="284" label="Save Chart" click="getBitmapData(BarChartSales)"/>
          </mx:Panel>
          <mx:Image id='img1' x="41" y="395" width="674" height="303"/>
          </mx:Application>