Hi Guys,
I am getting a Type Expected error when I am using the following simple line of code
Dim chart as new Chart()
I have searched extensively but am unable to find out why the error occurs or what to do about it.
I am trying to create a simple XY Column Graph with Positive(Blue) and negative(Red) values on the Y axis and Time on the X axis
Here is the code so far.
Hope you are able to shed some light on my mistake?Code:Imports System.Security.Cryptography.X509Certificates Imports System.Windows.Forms.DataVisualization.Charting Public Class Form1 'ColumnChartExample ' summary ' Windows Forms example for a column chart with time (seconds) on the X-axis ' and positive/negative values on the Y-axis. ' Positive values are displayed in blue; negative values are displayed in red. Inherits Form Dim chart As New Chart() Private chartArea As ChartArea Private series As Series Public AnalysisValues(10) As Integer Private Sub Form_Load() End Sub Private Sub Data() AnalysisValues = {1, 3, 4, 3, 2, 1, 0, -1, -3, -4} End Sub Public Sub New() ' Initialize the form Me.Text = "Column Chart Example" Me.Size = New Drawing.Size(900, 600) ' Create the chart control chart = New Chart() chart.Dock = DockStyle.Fill ' Create and configure the chart area chartArea = New ChartArea("MainArea") chartArea.AxisX.Title = "Time (seconds)" chartArea.AxisY.Title = "Value" ' Add a zero-crossing line on the Y-axis for clarity chartArea.AxisX.Crossing = 0 chartArea.AxisY.Crossing = 0 chartArea.AxisY.IntervalAutoMode = IntervalAutoMode.VariableCount ' Optional: customize grid lines chartArea.AxisX.MajorGrid.LineColor = Drawing.Color.LightGray chartArea.AxisY.MajorGrid.LineColor = Drawing.Color.LightGray chart.ChartAreas.Add(chartArea) ' Create and configure the data series series = New Series("DataSeries") series.ChartType = SeriesChartType.Column series.ChartArea = "MainArea" series.IsValueShownAsLabel = True series.LabelForeColor = Drawing.Color.Black ' Sample data: time in seconds and corresponding positive/negative values Dim data As New List(Of Tuple(Of Double, Double)) From { Tuple.Create(1.0, 15.0), Tuple.Create(2.0, -8.0), Tuple.Create(3.0, 22.0), Tuple.Create(4.0, -5.0), Tuple.Create(5.0, -18.0), Tuple.Create(6.0, 7.0), Tuple.Create(7.0, 0.0), Tuple.Create(8.0, -12.0), Tuple.Create(9.0, 30.0), Tuple.Create(10.0, -3.0) } ' Populate the series and color each column based on positive/negative value For Each point In data Dim dp As New DataPoint() dp.SetValueXY(point.Item1, point.Item2) dp.AxisLabel = point.Item1.ToString() ' X-axis label shows time in seconds ' Color logic: blue for positive, red for negative If point.Item2 >= 0 Then dp.Color = Drawing.Color.Blue Else dp.Color = Drawing.Color.Red End If series.Points.Add(dp) Next chart.Series.Add(series) ' Add a legend for clarity Dim legend As New Legend("MainLegend") legend.Docking = Docking.Top chart.Legends.Add(legend) ' Add the chart to the form Me.Controls.Add(chart) End Sub ' summary ' Entry point to run the form. Public Shared Sub Main() Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) Application.Run(New Form1()) '(New ColumnChartExample()) End Sub End Class
Regards,
Antony




Reply With Quote
