具有多个系列的Windows表单图表控件未呈现 [英] Windows form chart control with multiple series not rendering

查看:58
本文介绍了具有多个系列的Windows表单图表控件未呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天来我一直在研究图表控件,并且看到将 DataBindXY 与一个图表区域上的多个序列一起使用应该可以工作。但是我的不工作。我尝试过在设计表单中设置属性和在表单页面加载后在代码中创建系列。第一个系列将渲染,而第二个系列则不会渲染。我尝试将其拆分为2个子例程,并在加载时调用该子例程,但这也行不通。

I have been researching chart controls for a few days and have seen that using DataBindXY with multiple series on one chart area should work. However mine is not working. I have tried both setting properties in the design form and creating the series in code behind on form page load. The first series will render but the second will not. I tried splitting into 2 sub routines and calling the subroutines on load but that did not work either.

关于如何在1条线图上获得多个序列的任何想法? / p>

Any ideas on how to get multiple series on the 1 line graph?

    Chart1.Series.Add("EndBearing")
    Chart1.Series(0).ChartType = SeriesChartType.Line
    Chart1.Series(0).Points.DataBindXY(array1, array2)

    Chart1.Series.Add("Ult")
    Chart1.Series(0).ChartType = SeriesChartType.Line
    Chart1.Series(0).Points.DataBindXY(array3, array2)


推荐答案

请尝试以下操作:

            Dim myfont As New Font("Sans Serif", 20, FontStyle.Bold)
            dim rs as adodb.recordset  [connect your tablefield on table]
            'dim db as adodb.connection [connect your database]
            dim msg as string

            'Chart1
            Chart1.Titles.Add("")
            Chart1.Titles(0).Font = myfont

            Chart1.Series.Add("[series1]")
            Chart1.Series.Add("[series2]")
            Chart1.Series.Add("[series3]")
            Chart1.Series.Add("[series4]")

            Msg = "Select [grouping recored], Sum([series1]) As s1, Sum([series2]) As s2, Sum([series3]) As s3, Sum([series4]) As s4 "
            Msg = Msg & "From [table] "
            Msg = Msg & "Group By [grouping recored]"

            Rs = New ADODB.Recordset
            Rs.Open(Msg, Db, ADODB.CursorTypeEnum.adOpenStatic)
            While Rs.EOF <> True
                Chart1.Series("[series1]").Points.AddXY(Rs(0).Value, Rs(1).Value.ToString)
                Chart1.Series("[series2]").Points.AddXY(Rs(0).Value, Rs(2).Value)
                Chart1.Series("[series3]").Points.AddXY(Rs(0).Value, Rs(3).Value)
                Chart1.Series("[series4]").Points.AddXY(Rs(0).Value, Rs(4).Value)
                Rs.MoveNext()
            End While
            Rs.Close()                              

让我解释一下:
我调用的数据库表单加载,因此在这种情况下不需要dim db。

let me explain: database I call on form load so no need dim db on this case. it will cause an error.

    Dim Loc As String
    Dim Db As ADODB.Connection

        Loc = Application.StartupPath & "\Database\[databasename].mdb"
        Msg1 = "Provider=Microsoft.Jet.OLEDB.4.0;" & Chr(10)
        Msg1 = Msg1 & "Data Source='" & Loc & "';" & Chr(10)
        Msg1 = Msg1 & "Jet OLEDB:Database Password=[databasepass]& Chr(10)

    Try
        Db = New ADODB.Connection
        Db.Open(Msg1)
    Catch ex As Exception
        MsgBox("Can't connect to Database" & vbCrLf & ex.Message)
    End Try

将其放在form_load源上(用于sql连接或如何打开Excel文件作为参考,您可以在Internet上搜索如何使用它。)

put that on form_load source. (for sql connection or how to open excel file as reference you can search on internet how to used it.)

在这种情况下,您可以将垂直值(y轴)作为记录索引0,将其他索引作为水平(x轴)

on this open case. you can put vertical value (y axis) as record index 0, and other index as horizontal (x axis)

可能是这样的:

    Chart1.Series("[series1]").Points.AddXY(Rs(1).Value, Rs(0).Value)
    Chart1.Series("[series2]").Points.AddXY(Rs(2).Value, Rs(0).Value)
    Chart1.Series("[series3]").Points.AddXY(Rs(3).Value, Rs(0).Value)
    Chart1.Series("[series3]").Points.AddXY(Rs(4).Value, Rs(0).Value)

您可以尝试使用此代码。

you can try this code.

这是示例结果
示例图片

希望它可以帮助您和其他人。
谢谢

Hope it can help you and other. Thanks

这篇关于具有多个系列的Windows表单图表控件未呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆