We help IT Professionals succeed at work.

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

Murray Brown
Murray Brown asked
Last Modified: 2016-03-19

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

        ' 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)


            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


            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

        Catch ex As Exception
        End Try
    End Sub

Open in new window

Watch Question

Software Engineer
This one is on us!
(Get your first solution completely free - no credit card required)
Murray BrownASP.net/VBA/VSTO Developer


Thanks very much

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.