我需要在运行时绘制图表并使用 Active Reports 将其保存为jpg文件。
我已设法创建SectionReport
并向其添加ChartControl
:
Dim chartControl As New ChartControl()
Dim series As New GrapeCity.ActiveReports.Chart.Series
series.Type = Chart.ChartType.Bar3D
Dim objs As New List(Of Teste)()
objs.Add(New Teste With {.Nome = "TESTE1", .Valor = 15})
objs.Add(New Teste With {.Nome = "TESTE2", .Valor = 22})
objs.Add(New Teste With {.Nome = "TESTE3", .Valor = 10})
objs.Add(New Teste With {.Nome = "TESTE4", .Valor = 36})
Dim chartArea As New ChartArea()
chartControl.ChartAreas.Add(chartArea)
chartControl.DataSource = ConvertToDataTable(objs)
chartControl.Series.Add(series)
chartControl.Series(0).ValueMembersY = "Nome"
chartControl.Series(0).ValueMemberX = "Valor"
Dim rpt As New SectionReport()
rpt.DataSource = ConvertToDataTable(objs)
rpt.Sections.InsertPageHF()
rpt.Sections(0).BackColor = Color.LightGray
rpt.Sections.Insert(1, New Detail())
rpt.Sections(1).BackColor = Color.PeachPuff
rpt.Sections(1).Height = 1.5
rpt.Sections(0).Controls.Add(chartControl)
rpt.Run()
Export(rpt.Document, "C:\Testes\")
Export
方法有效并生成jpg,问题是图表没有出现在图片中;在它的位置,有一条消息说“无法绘制图表。”。我已经使用在Active Reports设计器上创建的图表测试了Export方法,并且它运行良好。
这是生成的jpg文件:
答案 0 :(得分:0)
我最终得到以下代码。我真的不知道为什么,但它有效。
Dim objs As New List(Of Teste)()
objs.Add(New Teste With {.Nome = "TESTE1", .Valor = 15})
objs.Add(New Teste With {.Nome = "TESTE2", .Valor = 22})
objs.Add(New Teste With {.Nome = "TESTE3", .Valor = 10})
objs.Add(New Teste With {.Nome = "TESTE4", .Valor = 36})
objs.Add(New Teste With {.Nome = "TESTE5", .Valor = 36})
objs.Add(New Teste With {.Nome = "TESTE6", .Valor = 36})
objs.Add(New Teste With {.Nome = "TESTE7", .Valor = 36})
objs.Add(New Teste With {.Nome = "TESTE8", .Valor = 36})
objs.Add(New Teste With {.Nome = "TESTE9", .Valor = 36})
Dim chartArea As New ChartArea(True)
Dim series As New Series()
For Each obj As Teste In objs
Dim pt As New DataPoint()
pt.XValue = obj.Nome
pt.YValues = New DoubleArray(New Double() {obj.Valor})
series.Points.Add(pt)
Next
series.ChartArea = chartArea
series.Type = ChartType.Bar2D
series.ColorPalette = ColorPalette.Iceberg
Dim chartControl As New ChartControl()
chartControl.DataSource = ConvertToDataTable(objs)
chartControl.Series.Add(series)
chartControl.ChartAreas.Add(chartArea)
Dim rpt As New SectionReport()
rpt.Sections.InsertPageHF()
rpt.Sections.Insert(1, New Detail())
rpt.PageSettings.Orientation = PageOrientation.Landscape
chartControl.Width = CSng(rpt.PageSettings.PaperWidth / 1.35)
chartControl.Height = CSng(rpt.PageSettings.PaperHeight / 5)
rpt.Sections(1).Controls.Add(chartControl)
rpt.Run()
Export(rpt.Document, "C:\Testes\")