Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland asked on

ASP.net Can't see legend percentages on pie chart

Hi

I am using the code below to generate a pie chart. I used the following two lines to show the percentages on the chart but they don't appear
            series1.Label = "#PERCENT{P2}"
            series1.LegendText = "#VALX"


    Sub oChart3(ByVal oChartWidth As Integer, ByVal oChartHeight As Decimal, oRed As String, ByVal oGreen As Decimal, ByVal oAdd_To_Panel As Panel)
        ' Initialize the Chart object    
        Dim ChartGreen As New Chart()
        'ChartData.ID = "ChartData"
        ChartGreen.Width = oChartWidth
        ChartGreen.Height = oChartHeight
        ChartGreen.BorderSkin.SkinStyle = BorderSkinStyle.Raised

        Dim legend1 As New Legend()

        ' Set the Legend properties
        legend1.Name = "Default"
        legend1.Docking = Docking.Bottom
        legend1.LegendStyle = LegendStyle.Row
        legend1.Alignment = System.Drawing.StringAlignment.Center

        legend1.BackColor = System.Drawing.Color.Transparent
        legend1.BorderColor = System.Drawing.Color.Black
        legend1.BorderWidth = 1
        ' Add the Legend to the Chart
        ChartGreen.Legends.Add(legend1)

        ' Initialize objects and elements
        Dim chartArea1 As New ChartArea()
        chartArea1.AxisX.Interval = 1

        chartArea1.Name = "ChartArea1"
        chartArea1.BackColor = System.Drawing.Color.White


        'chartArea1.BackGradientStyle = GradientStyle.LeftRight

        'chartArea1.AxisX.LabelStyle.Font = New System.Drawing.Font("Calibri", 0.5, System.Drawing.FontStyle.Regular)
        'chartArea1.AxisY.LabelStyle.Font = New System.Drawing.Font("Calibri", 2, System.Drawing.FontStyle.Regular)

        ChartGreen.ChartAreas.Add(chartArea1)

        Try
            Dim yValues As Double() = {oRed, oGreen}
            Dim xValues As String() = {"Green", "Delay"}


            Dim series1 As New Series()
            series1.Name = "Default"
            series1.ChartType = SeriesChartType.Pie
            '
            series1.BorderWidth = 1
            'following two lines used to change series line colors....
            series1.EmptyPointStyle.Color = Drawing.Color.Transparent
            series1.Color = Drawing.Color.DarkGreen

            ChartGreen.Series.Add(series1)

            series1.Points.DataBindXY(xValues, yValues)

            series1.Points(0).Color = System.Drawing.Color.MediumSeaGreen
            series1.Points(1).Color = System.Drawing.Color.Red

            series1.BorderColor = Drawing.Color.DarkTurquoise
            series1.BackGradientStyle = GradientStyle.LeftRight

            series1.ChartType = SeriesChartType.Pie

            series1.Label = "#PERCENT{P2}"
            series1.LegendText = "#VALX"

            series1("PieLabelStyle") = "Disabled"

            ChartGreen.ChartAreas("ChartArea1").Area3DStyle.Enable3D = True

            ChartGreen.Legends(0).Enabled = True


            oAdd_To_Panel.Controls.Add(ChartGreen)
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Sub

Open in new window

ASP.NET

Avatar of undefined
Last Comment
Murray Brown

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Robert Schutt

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Murray Brown

Thanks very much
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23