1 Reply Latest reply on Mar 4, 2008 11:47 AM by Starlover_jacob

    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
          Starlover_jacob Level 1
          hello,
          I am struggling with images for a while now and i have the solution for you.
          Its not the full solution, but the following code will take any component and copy it to an image.
          You only have to figure out how to save it server side.
          Greets, jacob

          working example:


          <?xml version="1.0" encoding="utf-8"?>
          <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Script>
          <![CDATA[
          import flash.display.BitmapData;
          import flash.geom.Matrix;
          public function takeImage():void
          {
          //set image dimensions
          mychartcopyimg.width=areachart1.width;
          mychartcopyimg.height=areachart1.height;


          //put original component into bitmapdata
          var bmpData:BitmapData = new BitmapData( areachart1.width, areachart1.height, true, 0xe4e4e4 ) ;
          bmpData.draw( areachart1,null,null,null,null,true ) ;
          //new matrix for copy image
          var m : Matrix = new Matrix() ;
          //scale the image to the size of the chart
          m.scale( mychartcopyimg.width / areachart1.width, mychartcopyimg.height / areachart1.height ) ;
          //draw the copyed chart into the image
          mychartcopyimg.graphics.beginBitmapFill( bmpData, m, false, true ) ;
          mychartcopyimg.graphics.drawRect( 0, 0, mychartcopyimg.width, mychartcopyimg.height ) ;
          mychartcopyimg.graphics.endFill();
          }
          ]]>
          </mx:Script>
          <mx:AreaChart x="29" y="96" id="areachart1" width="201" height="188">
          <mx:series>
          <mx:AreaSeries displayName="Series 1" yField=""/>
          </mx:series>
          </mx:AreaChart>
          <mx:Legend dataProvider="{areachart1}"/>
          <mx:Image x="364" y="143" id="mychartcopyimg"/>
          <mx:Button x="240" y="351" click="takeImage()" label="Take image"/>

          </mx:WindowedApplication>