Jordan
Jordan

Reputation: 363

Making Pie Chart 3D and showing Percentages

I have created this simple macro to form a pie chart from some data but I would like it to show percentages and preferably 3D as well. Does anyone know how to adjust this?

Sub Pie_Chart()

Dim Sh As Worksheet
Dim chrt As Chart

Set chrt = Nothing
Set Sh = ActiveWorkbook.Worksheets("Graphs")
Set chrt = Sh.Shapes.AddChart.Chart
With chrt

        'Data
        .ChartType = xlPie

        'Titles
        .HasTitle = True
        .ChartTitle.Characters.Text = Cells(i + 12, 2).Value
        .Hasvalues = True

        'legend
        .HasLegend = True

    End With


    End Sub

Upvotes: 1

Views: 2895

Answers (2)

QHarr
QHarr

Reputation: 84465

Or

Option Explicit

Public Sub Pie_Chart()

    Dim Sh As Worksheet, chrt As Chart

    Set Sh = ActiveWorkbook.Worksheets("Graphs")
    Set chrt = Sh.Shapes.AddChart2(262, xl3DPie).Chart
    With chrt
        .SetSourceData Source:=Range("Graphs!$A$1:$A$4") 'add some data
        .HasTitle = True
       ' .ChartTitle.Characters.Text = Cells(i + 12, 2).Value 'what is i?
        .HasLegend = True
        With .SeriesCollection(1)
            .ApplyDataLabels
            .DataLabels.ShowPercentage = True
            .DataLabels.ShowValue = False   
        End With
    End With
End Sub

Upvotes: 1

dwirony
dwirony

Reputation: 5450

Try this:

Sub Pie_Chart()

Dim Sh As Worksheet
Dim chrt As Chart

Set chrt = Nothing
Set Sh = ActiveWorkbook.Worksheets("Graphs")
Set chrt = Sh.Shapes.AddChart.Chart
With chrt

        'Data
        .ChartType = xl3DPie

        'Titles
        .HasTitle = True
        .ChartTitle.Characters.Text = Cells(i + 12, 2).Value
        .Hasvalues = True

        'Legend
        .HasLegend = True

        'Style
        .ChartStyle = 264
End With

End Sub

Upvotes: 0

Related Questions