自动命名图表标题和坐标轴

Name chart title and axes automatically

我使用这段代码在选定的数据范围内自动生成图表,但我也想在一次点击中自动给它一个标题和轴名称,例如我想将 x 轴命名为子部分,将 y 轴命名为计数我想给图表一个标题作为矩阵图我该怎么做。任何帮助真的意义重大 在此先感谢,对于给您带来的不便,我们深表歉意

Sub create_embedded_chart()
Dim oChartObj As ChartObject

Set oChartObj = ActiveSheet.ChartObjects.Add(Top:=0, Left:=0, Width:=50, Height:=50)
oChartObj.Chart.SetSourceData Sheets("Tracedata").Range("A1:C45")

End Sub

请测试下一个(更新的)代码:

Sub create_embedded_chart()
    Dim oChartObj As ChartObject

    Set oChartObj = ActiveSheet.ChartObjects.Add(top:=0, left:=0, width:=200, height:=200)
    oChartObj.Chart.SetSourceData Sheets("Tracedata").Range ("A1:C45")
    With oChartObj.Chart
        .HasTitle = True
        .chartTitle.text = "Matrix graph"
        With .Axes(xlValue)
            .HasTitle = True
            With .AxisTitle
                .Caption = "Count"
                .Font.Name = "Arial"
                .Font.Size = 10
                .Font.Italic = True
            End With
        End With
        With .Axes(xlCategory)
            .HasTitle = True
            .AxisTitle.text = "Subsection"
        End With
    End With
End Sub