2

誰かがこれの例を持っていますか?今夜、Googleは私の友達ではありません。FusionChartsの最新バージョンを持っています。グラフを画像ファイルとして保存してメールで送信する方法を見つけようとしています。

画像を保存してHTMLメールに挿入する方法を知っています。これは、他のグラフ製品で以前に行ったことがあります。Fusionchartsでこれを行う方法の1つの良い例をうまく説明することはできません。

ありがとう!

4

2 に答える 2

1

2つのオプション(wkhtmltoimageとPhantomJS。)が両方のステップバイステップの手順で説明されているサーバーサイドでチャート画像をエクスポートする最新のブログ投稿をチェックしてください。

ColdFusionの場合、次のコードを試すことができます。

例えば:

<cfexecute name="C:\Program Files\wkhtmltopdf\wkhtmltoimage.exe" arguments="--javascript-delay 10000 http://docs.fusioncharts.com/charts/Code/MyFirstChart/ms-weekly-sales-no-animation.html savedimage.png" />

上記のスクリプトの実行中に、次の引数を指定します。wkhtmltoimageを呼び出します。WebページのURLを渡します。画像が保存される画像ファイルのパスと名前(拡張子付き)を渡します。必要に応じて、追加の遅延により、チャートは完全にレンダリングされます。

于 2013-03-21T06:04:31.003 に答える
1

テンプレートで次のコードを使用し、そのテンプレートでimageSaveURLプロパティを指定します。

チャートは、チャートを再構築するために必要なすべてのデータを送信します。私の例では、ブラウザに提供していますが、ローカルに保存して、cfmail必要に応じて添付することもできます。

私はもともとfusionchartsフォーラムからこれを入手したと確信しています。これは、fusioncharts3.1用に更新されました。

<cfif structKeyExists(Form, "width") >
    <cfset width = int(Form.width) />
<cfelse>
    <cfset width = int(Form.Meta_Width) />
</cfif>
<cfif structKeyExists(Form, "height") >
    <cfset height = int(Form.height) />
<cfelse>
    <cfset height = int(Form.Meta_Height) />
</cfif>

<cfif structKeyExists(Form, "data") >
    <cfset Form.data = Form.data />
<cfelse>
    <cfif structKeyExists(Form, "stream") >
        <cfset Form.data = Form.stream />
    </cfif>
</cfif>

<cfset user = viewState.getValue("user", structNew()) />


<!--- Impose some limits to mitigate DOS attacks --->
<cfif Not (0 lte width and width lte 5000)>
    <cfthrow message="Width out of range." />
</cfif>
<cfif Not (0 lte height and height lte 5000)>
    <cfthrow message="Height out of range." />
</cfif>


<!--- Check if we have the chart data --->
<cfif Not StructKeyExists(Form, "data") or Not Len(Trim( Form.data ))>
    <cfthrow message="Image Data not supplied." />
</cfif>


<!--- Default background color is white --->
<cfif Not StructKeyExists(Form, "bgcolor") or Not Len(Trim( Form.bgcolor ))>
    <cfset Form.bgcolor = "FFFFFF" />
</cfif>


<cfset gColor = CreateObject("java", "java.awt.Color") />
<cfset chart = CreateObject("java", "java.awt.image.BufferedImage") />
<cfset chart.init( JavaCast("int", width), JavaCast("int", height), chart.TYPE_3BYTE_BGR) />
<cfset gr = chart.createGraphics() />
<cfset gr.setColor( gColor.decode("##" & Form.bgcolor) ) />
<cfset gr.fillRect(0, 0, JavaCast("int", width), JavaCast("int", height)) />

<!--- Get rows with pixels --->
<cfset rows = ListToArray(Form.data, ";") />

<cfloop from="1" to="#ArrayLen(rows)#" index="i">

    <cfset pixels = ListToArray(rows[i], ",") />
    <!--- Horizontal index (x scale) --->
    <cfset horizIndex = 0 />

    <cfloop from="1" to="#ArrayLen(pixels)#" index="j">

        <cfif ListLen(pixels[j], "_") eq 2>
            <!--- We have the color and the number of times it must be repeated --->
            <cfset color  = ListGetAt(pixels[j], 1, "_") />
            <cfset repeat = ListGetAt(pixels[j], 2, "_") />
        <cfelse>
            <!--- Background color; how many pixels to skip --->
            <cfset color  = "" />
            <cfset repeat = ListGetAt(pixels[j], 1, "_") />
        </cfif>

        <cfif Len(Trim(color))>

            <!---  If the hexadecimal code is less than 6 characters, prefix with 0 to get a 6 char color --->
            <cfif Len(Trim(color)) lt 6>
                <cfset color = RepeatString(0, 6 - Len(Trim(color))) & color />
            </cfif>

            <!--- Draw a horizontal line for the number of pixels we must repeat --->
            <cfset gr.setColor(gColor.decode("##" & color)) />
            <cfset gr.drawLine(JavaCast("int", horizIndex), JavaCast("int", i - 1), JavaCast("int", horizIndex + repeat -1), JavaCast("int", i - 1)) />
        </cfif>

        <cfset horizIndex = horizIndex + repeat />
    </cfloop>

</cfloop>

<!--- Get writer for Jpeg --->
<cfset writer = "" />
<cfset iter = CreateObject("java", "javax.imageio.ImageIO").getImageWritersByFormatName("jpg") />
<cfloop condition="iter.hasNext()">
    <cfset writer = iter.next() />
</cfloop>

<!--- Set Jpeg quality to maximum --->
<cfset jpgParams = CreateObject("java", "javax.imageio.plugins.jpeg.JPEGImageWriteParam").init( CreateObject("java", "java.util.Locale").init("en") ) />
<cfset jpgParams.setCompressionMode( jpgParams.MODE_EXPLICIT ) />
<cfset jpgParams.setCompressionQuality( 1 ) />

<!--- Write image to a memory stream --->
<cfset imageOutput = CreateObject("java", "java.io.ByteArrayOutputStream").init() />
<cfset writer.setOutput( CreateObject("java", "javax.imageio.stream.MemoryCacheImageOutputStream").init( imageOutput ) ) />
<cfset writer.write(JavaCast("null", 0), CreateObject("java", "javax.imageio.IIOImage").init(chart, JavaCast("null", 0), JavaCast("null", 0)), jpgParams) />

<!--- Stream the image to the browser (hint browser to display the Save dialog) --->
<cfset filename="whatever.jpg" />
<cfheader name="Content-Disposition" value="attachment; filename=""#filename#""">
<cfcontent type="image/jpeg" variable="#imageOutput.toByteArray()#">
于 2013-02-23T10:11:05.053 に答える