troubleshooting Question

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

Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland asked on
ASP.NET
2 Comments1 Solution266 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
Robert Schutt
Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros