如何使用c#绘制图表?

如何使用c#绘制图表?,c#,database,vb.net,winforms,charts,C#,Database,Vb.net,Winforms,Charts,我必须用c#画一个条形图。首先,我尝试使用vb.net,使用下面的System.Windows.Forms.DataVisualization.Chartingnamespace.code Dim strConn As string MyConString = "SERVER=localhost;" + "DATABASE=demo;" + "UID=root;" + "PASSWORD=root;"; Dim conn As New SqlConnection(strConn

我必须用c#画一个条形图。首先,我尝试使用vb.net,使用下面的
System.Windows.Forms.DataVisualization.Charting
namespace.code

    Dim strConn As  string MyConString = "SERVER=localhost;" + "DATABASE=demo;" + "UID=root;" + "PASSWORD=root;";
    Dim conn As New SqlConnection(strConn)

    Dim sqlProducts As String = "SELECT Top 8 ProductName, UnitsInStock FROM Products"
    Dim da As New MYSqlDataAdapter(sqlProducts, conn)
    Dim ds As New DataSet()
    da.Fill(ds, "Products")

    Dim ChartArea1 As ChartArea = New ChartArea()
    Dim Legend1 As Legend = New Legend()
    Dim Series1 As Series = New Series()
    Dim Chart1 = New Chart()
    Me.Controls.Add(Chart1)

    ChartArea1.Name = "ChartArea1"
    Chart1.ChartAreas.Add(ChartArea1)
    Legend1.Name = "Legend1"
    Chart1.Legends.Add(Legend1)
    Chart1.Location = New System.Drawing.Point(13, 13)
    Chart1.Name = "Chart1"
    Series1.ChartArea = "ChartArea1"
    Series1.Legend = "Legend1"
    Series1.Name = "Series1"
    Chart1.Series.Add(Series1)
    Chart1.Size = New System.Drawing.Size(800, 400)
    Chart1.TabIndex = 0
    Chart1.Text = "Chart1"

    Chart1.Series("Series1").XValueMember = "date"
    Chart1.Series("Series1").YValueMembers = "temperature"

    Chart1.DataSource = ds.Tables("flowchart")
它的工作原理和我用c#试过的完全一样

在最后三行中获取错误。我不知道该方法是否正确。

看起来像是一个属性,它返回

如果您想使用和属性,您需要像使用索引器()一样使用索引器

c1.Series["Series"].XValueMember = "date";
c1.Series["Series"].YValueMembers = "temperature";
在C语言中,当您在列表/集合或数组中提供参数时,应将其写入方括号
[]
。只有方法或函数的参数可以有圆括号
()
`

应该这样写

c1.Series["Series"].XValueMember = "date";`

错误到底是什么?最后三行出现错误,如错误1非发票成员'System.Windows.Forms.DataVisualization.Charting.Chart.Series'不能像方法一样使用。'在这三行上使用
[…]
而不是
(…)
。.working fine Lasse V.Karlsen。。
c1.Series["Series"].XValueMember = "date";`