Results 1 to 5 of 5

Thread: [RESOLVED] How to Visualize legend for each ChartArea

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    164

    Resolved [RESOLVED] How to Visualize legend for each ChartArea

    Hi all,
    I developed a Function that creates a Chart Area inside a chart.
    I tried to assign to each Chart Area a legend without success.

    A part of this Function is:

    Code:
    Private Sub _CreateStackedDrawKPI(ByVal MyChart As Chart, ByVal T As DataTable, ByVal titolo As String, ByVal NumChartArea As Integer, ByVal legenda As String)
       
    x = (From p In T.AsEnumerable()
                 Select p.Field(Of String)("Week") Distinct).ToArray()
            ' Order By p.Field(Of String)("Week")
    
    
            y1K = (From p In T.AsEnumerable()
                   Select p.Field(Of Integer)("Num_CS_RAB_Est_Att")).ToArray()
    
    
            y2K = (From p In T.AsEnumerable()
                   Select p.Field(Of Integer)("Num_CS_RAB_Est_Succ")).ToArray()
    
            y3 = (From p In T.AsEnumerable()
                  Select p.Field(Of Double)("CSSR")).ToArray()
    
            Dim ChartArea1 = New ChartArea()
    
            ChartArea1.Name = titolo
            MyChart.ChartAreas.Add(titolo)
            Dim Mylegend As New Legend
            Mylegend.Name = legenda
             MyChart.Legends.Add(legenda)
            MyChart.Legends(legenda).DockedToChartArea = titolo
            MyChart.Legends(titolo).IsDockedInsideChartArea = False
    ...
    This function is called in this way:
    Code:
    Dim aa As New MyFunctions
    		....
    		If Lista_KPI.Count = 1 Then
                    ChartKPI = New Chart
                    ChartKPI.Name = "Chart_KPI"
                    SplitContainer3.Panel2.Controls.Add(ChartKPI)
                    aa.CreateStackedDrawKPI(ChartKPI, T_Data1, NomeContatore, Lista_KPI.Count, Titolo)
                End If
    
    
                If Lista_KPI.Count = 2 Then
                    aa.CreateStackedDrawKPI(ChartKPI, T_Data1, NomeContatore, Lista_KPI.Count, Titolo)
                End If
    Lista_KPI is a list of string of 2 elements: CSSR and DCR
    NomeContatore is a string and it is equal at first step to value "CSSR" and in second Step to "DCR"
    Titolo is a string and it is equal at first step to value "CSSR" and in second Step to "DCR".
    Titolo is equal to NomeContatore
    Each Element of list calls the function above.

    Issue s that both legend and also Title are showed always in first Chart Area

    Name:  image.jpg
Views: 310
Size:  20.8 KB

    Any suggestion?
    Thank in advanced
    gio
    Last edited by giodepa; Jan 16th, 2021 at 03:08 AM.

  2. #2
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: How to Visualize legend for each Chart Area

    As you set the legends outside the chartarea, it is possible that they take both the same default position on the chart.
    Try MyChart.Legends(titolo).IsDockedInsideChartArea = true just to verify that

    you can change the position of the legend with legend.position : https://docs.microsoft.com/fr-fr/dot...tframework-4.8
    Last edited by Delaney; Jan 16th, 2021 at 05:49 AM.
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    164

    Re: How to Visualize legend for each Chart Area

    Hi Delaney,
    link that you provided doesn't work
    I already tried legend insideDockArea
    This is result:
    Name:  image1.jpg
Views: 207
Size:  21.7 KB

  4. #4
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: How to Visualize legend for each ChartArea

    I don't know what's happened with the link. I corrected it
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    164

    Re: How to Visualize legend for each ChartArea

    Hi All,
    finally I found issue!!!
    Code above is correct but for each series it is necessary to specify legend too:

    Code:
    series1.Legend = titolo
    and result is:
    Name:  image2.jpg
Views: 190
Size:  26.7 KB

    gio

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width