简体   繁体   English

如何在VB.Net图表上显示多个图例

[英]How do I show multiple legends on a VB.Net Chart

My code creates a MS Chart with one or more ChartAreas and I want to have a separate legend for each ChartArea My code is as below: 我的代码使用一个或多个ChartAreas创建了一个MS Chart,我希望每个ChartArea都有一个单独的图例。我的代码如下:

                For tblNum = 0 To (dsData.Tables.Count - 1)

                tblName = dsData.Tables(tblNum).TableName
                caTag = dtReport.Rows(tblNum).Item("caTag")
                If (dtReport.Rows(tblNum).Item("CAnum") > CAnum) Then
                    CAnum = dtReport.Rows(tblNum).Item("CAnum")
                    myChart.ChartAreas.Add(caTag)
                    myChart.Legends.Add(caTag)
                    With myChart.Legends(caTag)
                        .Docking = Docking.Bottom
                        .DockedToChartArea = caTag
                        .IsDockedInsideChartArea = False
                        .TableStyle = LegendTableStyle.Wide
                        .Alignment = StringAlignment.Center
                        .Enabled = True
                    End With
                    If (caCount > 1) Then
                        CAindex += 1
                        myChart.Titles.Add(caTag)
                        With myChart.Titles(CAindex)
                            .Docking = Docking.Top
                            .DockedToChartArea = caTag
                            .IsDockedInsideChartArea = False
                            .Alignment = ContentAlignment.TopCenter
                            .Font = New System.Drawing.Font("Times New Roman", 14, FontStyle.Bold)
                            .Text = caTag
                        End With
                    End If
                Else
                    myChart.Legends(caTag).Enabled = True
                End If

However when I run the code only a single Legend is visible containing all series from both ChartAreas as below: Legend-1.jpg Can anyone help me please ? 但是,当我运行代码时,只有一个图例可见,其中包含来自两个ChartAreas的所有系列,如下所示: Legend-1.jpg有人可以帮我吗?

I have found the answer to my own question. 我找到了自己问题的答案。 I needed to assign the correct legend to each series as follows: 我需要为每个系列分配正确的图例,如下所示:

myChart.Series(tblName).Legend = caTag

Now both legends are shown with the appropriate series names 现在,两个图例都显示了适当的系列名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM