在ASP.NET中导出图表 [英] Export Chart in ASP.NET
本文介绍了在ASP.NET中导出图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要求将图表导出为Excel和PDF格式。
我可以使用itextsharp和SQLDATASOURCE将带有2轴的图表导出为pdf。事情是我有3轴(X,Y,辅助Y)图表,所以我无法将图表导出为PDF / Excel。我使用Sql server 2008来拉取图表轴的值。
任何人都可以指导我这个...我的脑袋毁了:(
先谢谢。
Hi ,
I have a requirement to export the chart to Excel and PDF.
I can able to export the chart with 2 axis to pdf using itextsharp and SQLDATASOURCE. The thing is I have 3 axis(X,Y,Secondary Y) Chart so I couldn''t able to export the chart to PDF/Excel.And I am using Sql server 2008 to pull values for chart axis.
Can anyone please guide me on this..its ruin my head :(
Thanks in Advance.
推荐答案
Imports System.Web.UI.DataVisualization
Imports System.Web.UI.DataVisualization.Charting
Dim srs As Series = chtTotal.Series.Add("srsTotal")
Dim lgn As Legend = chtTotal.Legends.Add("legTotal")
Dim ds As DataSet = Bugs.GetCallListForReviewChartPie(Session("user_id"), lblClients.Text, txtFromDate.Text, txtToDate.Text)
If ds.Tables(0).Rows.Count > 0 Then
chtTotal.DataSource = ds.Tables(0)
lgn.LegendStyle = LegendStyle.Table
lgn.Alignment = StringAlignment.Center
lgn.Docking = Docking.Bottom
srs.ChartType = SeriesChartType.Pie
srs.ShadowOffset = 2
srs.Font = New Font("Times New Format", 7.0F)
srs.IsValueShownAsLabel = True
Dim yValues(1) As Integer
Dim xValues(1) As String
For j As Integer = 0 To ds.Tables(0).Rows.Count - 1
xValues(j) = ds.Tables(0).Rows(j).Item("Category")
If ds.Tables(0).Rows.Count = 1 Then
xValues(j + 1) = IIf(ds.Tables(0).Rows(j).Item("Category") = "CR", "PR", "CR")
End If
Next
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
yValues(i) = ds.Tables(0).Rows(i).Item("Total")
Next
srs.Points.DataBindY(yValues)
For pointIndex As Integer = 0 To srs.Points.Count - 1
srs.Points(pointIndex).LegendText = xValues(pointIndex)
srs.Points(pointIndex).ToolTip = xValues(pointIndex) & " (" & yValues(pointIndex) & ")"
srs.Points(pointIndex).LegendToolTip = xValues(pointIndex) & " (" & yValues(pointIndex) & ")"
Next
srs.PostBackValue = "#INDEX"
srs.LegendPostBackValue = "#INDEX"
srs.Points(0).Font = New Font("Times New Format", 7.0F)
chtTotal.Series("srsTotal").SetCustomProperty("PieLabelStyle", "Disabled")
For pointIndex As Integer = 0 To srs.Points.Count - 1
If yValues(pointIndex) = "0" Then
srs.Points(pointIndex).PostBackValue = ""
srs.Points(pointIndex).LegendPostBackValue = ""
End If
Next
If Not txtID.Text = "" Then
srs.Points(IIf(txtID.Text = "PR", 1, 0)).Font = New Font("Times New Format", 9.0F, FontStyle.Bold)
srs.Points(IIf(txtID.Text = "PR", 1, 0)).BorderColor = Color.Black
srs.Points(IIf(txtID.Text = "PR", 1, 0)).BorderWidth = 4
End If
chtTotal.Width = 500
If File.Exists(tmpChartName) Then File.Delete(tmpChartName)
chtTotal.SaveImage(tmpChartName, ChartImageFormat.Png)
chtTotal.Legends.RemoveAt(0)
chtTotal.Width = 200
Else
chtTotal.Visible = False
Session("Message") = "No Records."
Master.ShowMessage()
End If
i在mschart的帮助下动态创建。
我的图表自动导出到文件中。我不知道如何解决这个问题。因为导出编码不包含在我的应用程序中。
My charts automatically exported into a file. I don''t know how to solve that problem. Because export coding is not included in my application.
这篇关于在ASP.NET中导出图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文