<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>schmichael&#039;s blog &#187; fusioncharts</title>
	<atom:link href="http://blog.schmichael.com/tag/fusioncharts/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.schmichael.com</link>
	<description>good good study, day day up</description>
	<lastBuildDate>Mon, 02 Aug 2010 17:28:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>BitBucket Project for Python FusionCharts Code</title>
		<link>http://blog.schmichael.com/2009/04/08/bitbucket-project-python-fusioncharts/</link>
		<comments>http://blog.schmichael.com/2009/04/08/bitbucket-project-python-fusioncharts/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 22:51:05 +0000</pubDate>
		<dc:creator>Michael Schurter</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[bitbucket]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[fusioncharts]]></category>
		<category><![CDATA[hg]]></category>
		<category><![CDATA[pil]]></category>

		<guid isPermaLink="false">http://michael.susens-schurter.com/blog/?p=626</guid>
		<description><![CDATA[After my last post on FusionCharts, someone was nice enough to e-mail me some a Django snippet for exporting FusionCharts as images, so I decided I might as well put the code in a public repository. While I prefer Bazaar &#8230; <a href="http://blog.schmichael.com/2009/04/08/bitbucket-project-python-fusioncharts/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://michael.susens-schurter.com/blog/2009/04/02/image-exporter-for-fusion-charts/">After my last post on FusionCharts</a>, someone was nice enough to e-mail me some a <a href="http://djangoproject.com">Django</a> snippet for exporting <a href="http://fusioncharts.com">FusionCharts</a> as images, so I decided I might as well put the code in a public repository.</p>
<p>While I prefer Bazaar out of all the DVCSes, it seems Mercurial has captured the hearts and minds of the Python empire, so I created the <a href="http://bitbucket.org/schmichael/python-fusioncharts/">python-fusioncharts project</a> on <a href="http://bitbucket.org/">BitBucket</a>.</p>
<p>If you use Python and FusionCharts, I&#8217;d love to add more snippets!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schmichael.com/2009/04/08/bitbucket-project-python-fusioncharts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Image Exporter for Fusion Charts</title>
		<link>http://blog.schmichael.com/2009/04/02/image-exporter-for-fusion-charts/</link>
		<comments>http://blog.schmichael.com/2009/04/02/image-exporter-for-fusion-charts/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 21:02:30 +0000</pubDate>
		<dc:creator>Michael Schurter</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[fusioncharts]]></category>
		<category><![CDATA[pil]]></category>

		<guid isPermaLink="false">http://michael.susens-schurter.com/blog/?p=620</guid>
		<description><![CDATA[I wrote an image exporter for Fusion Charts while working for YouGov/Polimetrix, and someone recently asked if they could use it as well. You&#8217;ll have to alter it a bit because it was written for a custom CherryPy-based framework. It &#8230; <a href="http://blog.schmichael.com/2009/04/02/image-exporter-for-fusion-charts/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I wrote an image exporter for <a href="http://www.fusioncharts.com/">Fusion Charts</a> while working for <a href="http://www.polimetrix.com/">YouGov/Polimetrix</a>, and someone recently asked if they could use it as well.</p>
<p>You&#8217;ll have to alter it a bit because it was written for a custom <a href="http://cherrypy.org">CherryPy</a>-based framework.  It works with Fusion Charts 3.1 (and 3.0 with trivial changes to the POST variables being read).</p>
<p>The only dependency is on <a href="http://www.pythonware.com/products/pil/">PIL</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">StringIO</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">StringIO</span>
<span style="color: #ff7700;font-weight:bold;">import</span> Image
<span style="color: #ff7700;font-weight:bold;">import</span> ImageColor
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> cherrypy
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> str2color<span style="color: black;">&#40;</span>val<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> ImageColor.<span style="color: black;">getrgb</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'#'</span>+val.<span style="color: black;">ljust</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span>, <span style="color: #483d8b;">'0'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> SaveImagePage<span style="color: black;">&#40;</span>LoggedInPage<span style="color: black;">&#41;</span>:  <span style="color: #808080; font-style: italic;"># Custom framework specific -- remove</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> control<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, page, meta_width=<span style="color: #483d8b;">''</span>, meta_height=<span style="color: #483d8b;">''</span>, meta_bgColor=<span style="color: #483d8b;">'ffffff'</span>, stream=<span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># Convert 3.1 parameters to 3.0 style as they made more sense</span>
        width = meta_width
        height = meta_height
        bgcolor = meta_bgColor
        data = stream
&nbsp;
        <span style="color: #808080; font-style: italic;"># Split the data into rows using ; as the spearator</span>
        rows = data.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">';'</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Create image</span>
        bgcolor = str2color<span style="color: black;">&#40;</span>bgcolor<span style="color: black;">&#41;</span>
        im = Image.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'RGB'</span>, <span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>width<span style="color: black;">&#41;</span>, <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>height<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>, bgcolor<span style="color: black;">&#41;</span>
        imcore = im.<span style="color: black;">load</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">for</span> y, row <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">enumerate</span><span style="color: black;">&#40;</span>rows<span style="color: black;">&#41;</span>:
            x = <span style="color: #ff4500;">0</span>
&nbsp;
            <span style="color: #808080; font-style: italic;"># Split row into pixels</span>
            pixels = row.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">for</span> pixel <span style="color: #ff7700;font-weight:bold;">in</span> pixels:
                <span style="color: #808080; font-style: italic;"># Split pixel into color and repeat value</span>
                color, repeat = pixel.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'_'</span><span style="color: black;">&#41;</span>
                repeat = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>repeat<span style="color: black;">&#41;</span>
&nbsp;
                <span style="color: #ff7700;font-weight:bold;">if</span> color == <span style="color: #483d8b;">''</span>:
                    <span style="color: #808080; font-style: italic;"># Empty color == background color</span>
                    color = bgcolor
                <span style="color: #ff7700;font-weight:bold;">else</span>:
                    <span style="color: #808080; font-style: italic;"># Pad color to 6 characters</span>
                    color = str2color<span style="color: black;">&#40;</span>color<span style="color: black;">&#41;</span>
&nbsp;
                <span style="color: #ff7700;font-weight:bold;">while</span> repeat:
                    <span style="color: #808080; font-style: italic;"># Add pixels 1-at-a-time since putdata() doesn't work</span>
                    imcore<span style="color: black;">&#91;</span>x, y<span style="color: black;">&#93;</span> = color
                    x += <span style="color: #ff4500;">1</span>
                    repeat -= <span style="color: #ff4500;">1</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Save image into file like object</span>
        imstr = <span style="color: #dc143c;">StringIO</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        im.<span style="color: black;">save</span><span style="color: black;">&#40;</span>imstr, <span style="color: #483d8b;">'PNG'</span>, quality=<span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set HTTP headers -- CherryPy specific code</span>
        cherrypy.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'content-type'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'image/png'</span>
        cherrypy.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'content-disposition'</span><span style="color: black;">&#93;</span> = \
                <span style="color: #483d8b;">'attachment; filename=&quot;Chart.png'</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Return image as string, your framework may be different</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> imstr.<span style="color: black;">getvalue</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.schmichael.com/2009/04/02/image-exporter-for-fusion-charts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
