I am trying to generate some charts and render them to an image. If I put an chart on the form, populate it with data and then call Chart.DrawToBitmap
it works fine. However, if I create the Chart as an object in my code then it just renders an empty image.
Dim Chart1 As New System.Windows.Forms.DataVisualization.Charting.Chart
.Width = 100
.Height = 100
Dim ChartSeries As New System.Windows.Forms.DataVisualization.Charting.Series
.Name = "TestSeries"
.ChartType = DataVisualization.Charting.SeriesChartType.Line
' Add sample data
For i As Integer = 1 To 10
.Points.AddXY(i, i * 2)
End With ' ChartSeries
' Add the series to the Chart
End With ' Chart1
Dim img As New Bitmap(100, 100)
Chart1.DrawToBitmap(bmp, New Rectangle(0, 0, 100, 100))
The above code just renders a blank image.
But as I said, if I drag a Chart object from the toolbox and put it on the form and populate the series, it renders to an image just fine.
There must be something that I'm neglecting to do.