Fri Mar 27, 2015 9:47 pm
Thanks Betsy. I was able to plot my chart now using your samples.
I have two follow-up questions.
- I am trying to set the primary axis title, but it is not getting displayed.
- I am trying to plot a series on the secondary axis but I can't find the "UseSecondAxis" property show up. I have attached the code I am using.
private Sub TestChart
Dim pres As New Presentation()
'insert chart
Dim rect As New RectangleF(pres.SlideSize.Size.Width / 2 - 200, 0, 400, 250)
Dim chart As IChart = pres.Slides(0).Shapes.AppendChart(Spire.Presentation.Charts.ChartType.ColumnClustered, rect)
'add chart Title
chart.ChartTitle.TextProperties.Text = "Report"
chart.ChartTitle.TextProperties.IsCentered = True
chart.ChartTitle.Height = 30
chart.HasTitle = True
chart.PrimaryCategoryAxis.TextRotationAngle = 270
chart.ChartLegend.Position = ChartLegendPositionType.Bottom
chart.PrimaryValueAxis.Title.IsOverlay = False
chart.PrimaryValueAxis.Title.TextProperties.Text = "Primary Axis"
'load data from XML file to datatable
Dim dataTable As System.Data.DataTable = LoadData()
'load data from datatable to chart
InitChartData(chart, dataTable)
chart.Series.SeriesLabel = chart.ChartData("B1", "C1")
chart.Categories.CategoryLabels = chart.ChartData("A2", "A4")
chart.Series(0).Values = chart.ChartData("B2", "B4")
chart.Series(0).Fill.FillType = FillFormatType.Solid
chart.Series(0).Fill.SolidColor.KnownColor = KnownColors.Brown
chart.Series(1).Values = chart.ChartData("C2", "C4")
chart.Series(1).Fill.FillType = FillFormatType.Solid
chart.Series(1).Fill.SolidColor.KnownColor = KnownColors.Green
End Sub
Private Function LoadData() As System.Data.DataTable
Dim dt As System.Data.DataTable
Dim dr As System.Data.DataRow
dt = New System.Data.DataTable
dt.Columns.Add("Date", GetType(String))
dt.Columns.Add("Series 1", GetType(Double))
dt.Columns.Add("Series 2", GetType(Double))
dr = dt.NewRow
dr(0) = "03/23/2015"
dr(1) = 10
dr(2) = 25
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "03/24/2015"
dr(1) = 20
dr(2) = 50
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "03/25/2015"
dr(1) = 30
dr(2) = 75
dt.Rows.Add(dr)
Return dt
End Function
'function to load data from DataTable to IChart
Private Sub InitChartData(ByVal chart As IChart, ByVal dataTable As System.Data.DataTable)
For c As Integer = 0 To dataTable.Columns.Count - 1
chart.ChartData(0, c).Text = dataTable.Columns(c).Caption
Next
For r As Integer = 0 To dataTable.Rows.Count - 1
Dim data As Object() = dataTable.Rows(r).ItemArray
For c As Integer = 0 To data.Length - 1
chart.ChartData(r + 1, c).Value = data(c)
Next
Next
End Sub