Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on Can't see legend percentages on pie chart


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

Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown


Thanks very much