如何在 ASP.Net 中将 FusionChart 导出为图像

发布于 2024-10-17 11:33:33 字数 81 浏览 5 评论 0原文

我们正在使用融合图表的免费版本,想知道是否有一种方法可以在不使用任何第三方组件的情况下将生成的图表导出到图像。我们使用 ASP.Net 来生成图表。

We are using the free version of fusion charts and want to know is there a way to export the generated chart to image without using any third party components. We are using the ASP.Net for generating the charts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

世俗缘 2024-10-24 11:33:34

解决方案

经过对这个主题的研究,我找到了一个有用的解决方案。

为此,我们需要 Bytecout 的免费软件来将 swf 转换为图像。可以从此链接下载该文件。

然后我们需要注册 COM dll 并将引用添加到我们的项目中。进一步使用请参考下文

Protected Sub btnSwf2ImgConverter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim swfobj As New SWFToImage.SWFToImageObject
    swfobj.InitLibrary("demo", "demo")
    swfobj.InputSWFFileName = Server.MapPath("dumps/swf/") & "FCF_MSColumn3D.swf"
    If ddlImageExtension.SelectedValue = "jpg" Then
        swfobj.ImageOutputType = TImageOutputType.iotJPG
        ext = ".jpg"
    Else
        If ddlImageExtension.SelectedValue = "gif" Then
            swfobj.ImageOutputType = TImageOutputType.iotGIF
            ext = ".gif"
        Else
            If ddlImageExtension.SelectedValue = "png" Then
                swfobj.ImageOutputType = TImageOutputType.iotPNG
                ext = ".png"
            Else
                If ddlImageExtension.SelectedValue = "bmp" Then
                    swfobj.ImageOutputType = TImageOutputType.iotBMP
                    ext = ".bmp"
                End If
            End If
        End If
    End If

    filenm = "FCF_Column3D" & ext
    swfobj.Execute_Begin()
    'swfobj.Execute()
    swfobj.Execute_SetVariable("dataXML", "<graph animation='0' formatNumber='1' divLineColor='ff5904' divLineAlpha='20' alternateHGridAlpha='5'  canvasBorderColor='666666'  baseFontColor='666666' showAlternateHGridColor='1' AlternateHGridColor='ff5904'  anchorSides='3' rotateNames='1' caption='Daily Reports' yAxisMinValue='0' yAxisMaxValue='1'  xAxisName='Day-Month-Year' yAxisName='Percentage' decimalPrecision='2'  numdivlines='8' numVdivlines='16' showhovercap='1'  formatNumberScale='0'> <categories> <category name='1-Jun-2010' showName='1' /> <category name='2-Jun-2010' showName='1' /> <category name='3-Jun-2010' showName='1' /> <category name='4-Jun-2010' showName='1' /> <category name='5-Jun-2010' showName='1' /> <category name='6-Jun-2010' showName='1' /> <category name='7-Jun-2010' showName='1' /> <category name='8-Jun-2010' showName='1' /> <category name='9-Jun-2010' showName='1' /> <category name='10-Jun-2010' showName='1' /> <category name='11-Jun-2010' showName='1' /> <category name='12-Jun-2010' showName='1' /> <category name='13-Jun-2010' showName='1' /> <category name='14-Jun-2010' showName='1' /> <category name='15-Jun-2010' showName='1' /> <category name='Aggregate' showName='1' /></categories><dataset  showValues='0' alpha='80' showAnchors='1' seriesname='Answered Percent' color='#f07979' lineThickness='2'><set name='Month' value='97.6'/><set name='Month' value='98.2'/><set name='Month' value='99.3'/><set name='Month' value='99.6'/><set name='Month' value='95.2'/><set name='Month' value='99.3'/><set name='Month' value='99.3'/><set name='Month' value='98.8'/><set name='Month' value='97.5'/><set name='Month' value='96.3'/><set name='Month' value='98.6'/><set name='Month' value='99.1'/><set name='Month' value='99.3'/><set name='Month' value='99.6'/><set name='Month' value='99.2'/><set name='Month' value='98.38'/></dataset></graph>")
    swfobj.Execute_SetVariable("chartWidth", "750")
    swfobj.Execute_SetVariable("chartHeight", "600")
    swfobj.ImageWidth = 600
    swfobj.ImageHeight = 500
    Threading.Thread.Sleep(10000)

    swfobj.Execute_GetImage()
    swfobj.SaveToFile(Server.MapPath("dumps/images/" & filenm))
    swfobj.Execute_End()
    Call DownloadImage(filenm)
End Sub

Public Sub DownloadImage(ByVal fn As String)
    Image1.ImageUrl = "~/dumps/images/" & fn
    Dim fi As New FileInfo(Server.MapPath("dumps/images/" & fn))
    HttpContext.Current.Response.Clear()
    HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", fn))
    HttpContext.Current.Response.ContentType = "image/" & DropDownList1.SelectedValue
    Response.WriteFile(fi.FullName)
    Response.Flush()
    fi.Delete()
    Response.End()

End Sub

这里animation='0'起着非常重要的作用,它指定融合图表swf,必须在没有动画的情况下加载。另外,如果我们让代码休眠 1 或 2 秒,swf 将完全加载,并且图像将转换为所选格式,这是可取的。

希望这对像我这样的人有用。 :-)

SOLUTION

After a research on this topic, I have found a useful solution for this.

For that we need to have a freeware from Bytecout to convert swf to image. This can be downloaded from this link.

Then we need to register the COM dlls and add the reference to our project. Refer to the below for further usage

Protected Sub btnSwf2ImgConverter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim swfobj As New SWFToImage.SWFToImageObject
    swfobj.InitLibrary("demo", "demo")
    swfobj.InputSWFFileName = Server.MapPath("dumps/swf/") & "FCF_MSColumn3D.swf"
    If ddlImageExtension.SelectedValue = "jpg" Then
        swfobj.ImageOutputType = TImageOutputType.iotJPG
        ext = ".jpg"
    Else
        If ddlImageExtension.SelectedValue = "gif" Then
            swfobj.ImageOutputType = TImageOutputType.iotGIF
            ext = ".gif"
        Else
            If ddlImageExtension.SelectedValue = "png" Then
                swfobj.ImageOutputType = TImageOutputType.iotPNG
                ext = ".png"
            Else
                If ddlImageExtension.SelectedValue = "bmp" Then
                    swfobj.ImageOutputType = TImageOutputType.iotBMP
                    ext = ".bmp"
                End If
            End If
        End If
    End If

    filenm = "FCF_Column3D" & ext
    swfobj.Execute_Begin()
    'swfobj.Execute()
    swfobj.Execute_SetVariable("dataXML", "<graph animation='0' formatNumber='1' divLineColor='ff5904' divLineAlpha='20' alternateHGridAlpha='5'  canvasBorderColor='666666'  baseFontColor='666666' showAlternateHGridColor='1' AlternateHGridColor='ff5904'  anchorSides='3' rotateNames='1' caption='Daily Reports' yAxisMinValue='0' yAxisMaxValue='1'  xAxisName='Day-Month-Year' yAxisName='Percentage' decimalPrecision='2'  numdivlines='8' numVdivlines='16' showhovercap='1'  formatNumberScale='0'> <categories> <category name='1-Jun-2010' showName='1' /> <category name='2-Jun-2010' showName='1' /> <category name='3-Jun-2010' showName='1' /> <category name='4-Jun-2010' showName='1' /> <category name='5-Jun-2010' showName='1' /> <category name='6-Jun-2010' showName='1' /> <category name='7-Jun-2010' showName='1' /> <category name='8-Jun-2010' showName='1' /> <category name='9-Jun-2010' showName='1' /> <category name='10-Jun-2010' showName='1' /> <category name='11-Jun-2010' showName='1' /> <category name='12-Jun-2010' showName='1' /> <category name='13-Jun-2010' showName='1' /> <category name='14-Jun-2010' showName='1' /> <category name='15-Jun-2010' showName='1' /> <category name='Aggregate' showName='1' /></categories><dataset  showValues='0' alpha='80' showAnchors='1' seriesname='Answered Percent' color='#f07979' lineThickness='2'><set name='Month' value='97.6'/><set name='Month' value='98.2'/><set name='Month' value='99.3'/><set name='Month' value='99.6'/><set name='Month' value='95.2'/><set name='Month' value='99.3'/><set name='Month' value='99.3'/><set name='Month' value='98.8'/><set name='Month' value='97.5'/><set name='Month' value='96.3'/><set name='Month' value='98.6'/><set name='Month' value='99.1'/><set name='Month' value='99.3'/><set name='Month' value='99.6'/><set name='Month' value='99.2'/><set name='Month' value='98.38'/></dataset></graph>")
    swfobj.Execute_SetVariable("chartWidth", "750")
    swfobj.Execute_SetVariable("chartHeight", "600")
    swfobj.ImageWidth = 600
    swfobj.ImageHeight = 500
    Threading.Thread.Sleep(10000)

    swfobj.Execute_GetImage()
    swfobj.SaveToFile(Server.MapPath("dumps/images/" & filenm))
    swfobj.Execute_End()
    Call DownloadImage(filenm)
End Sub

Public Sub DownloadImage(ByVal fn As String)
    Image1.ImageUrl = "~/dumps/images/" & fn
    Dim fi As New FileInfo(Server.MapPath("dumps/images/" & fn))
    HttpContext.Current.Response.Clear()
    HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", fn))
    HttpContext.Current.Response.ContentType = "image/" & DropDownList1.SelectedValue
    Response.WriteFile(fi.FullName)
    Response.Flush()
    fi.Delete()
    Response.End()

End Sub

Here animation='0' plays a very important role, it specifies the fusion chart swf that, it must be loaded without animation. Also it is advisable if we sleep the code for 1 or 2 sec the swf would be loaded completely and image is converted to the selected format.

Hope this would be useful for someone like me. :-)

请远离我 2024-10-24 11:33:34
  1. 屏幕截图。
  2. 许可它。

当然,还有免费的 Asp.net 图表控件 (此处)。 此处 是如何使用这些工具导出的示例。

  1. Screen capture.
  2. License it.

Of course, there's also the free Asp.net charting controls (here). Here's an example of how to export with those tools.

記憶穿過時間隧道 2024-10-24 11:33:34

FusionCharts 团队开发了一个 .NET 程序集,使您能够在服务器上导出图表,而无需在浏览器中加载图表。

您可以通过写信给 FusionCharts 支持来获取它:http://www.fusioncharts.com/contact/

这仅适用于 FusionCharts v3 图表。

FusionCharts Team has developed a .NET assembly which will enable you to export chart at server without loading the chart in the browser.

You can have it by writing to FusionCharts Support at http://www.fusioncharts.com/contact/.

This only works for FusionCharts v3 charts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文