无法设置Excel图表样式

时间:2016-12-01 21:23:34

标签: excel vb.net charts

以下是我的代码,

Public Sub createdonutchart(Chartrange1 As String, chartrange2 As String, L1 As Integer, T1 As Integer, W1 As Integer, H1 As Integer, targetsheet As Worksheet, charttitle As String)

        Dim oChart As Excel.Chart
        Dim MyCharts As Excel.ChartObjects
        Dim MyCharts1 As Excel.ChartObject
        MyCharts = targetsheet.ChartObjects
        MyCharts1 = MyCharts.Add(L1, T1, W1, H1)
        oChart = MyCharts1.Chart

        With oChart
            Dim chartRange As Excel.Range
            chartRange = targetsheet.Range(Chartrange1, chartrange2)
            .SetSourceData(chartRange)
            .PlotBy = Excel.XlRowCol.xlColumns
            .ChartType = Excel.XlChartType.xlDoughnut
            .ChartStyle = 3
            .ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowNone)
            .HasLegend = True
            .Legend.Position = Excel.XlLegendPosition.xlLegendPositionRight
            .HasTitle = True
            .ChartTitle.Text = charttitle
        End With

    End Sub

我使用chart.chartstyle = 3将图表样式更改为3,但excel仍显示基本图表样式的图表,请参阅附图。

请帮忙 enter image description here

1 个答案:

答案 0 :(得分:0)

' 3'不是有效的图表类型...

请参阅MSDN页面获取XlChartType枚举,然后选择其中一个。

链接: https://msdn.microsoft.com/en-us/library/office/ff838409.aspx