Excel VBA-调整颜色线和X轴间隔
我使用Excel VBA创建了一个图表,我想调整线条颜色和x轴间隔 代码如下:Excel VBA-调整颜色线和X轴间隔,vba,excel,charts,Vba,Excel,Charts,我使用Excel VBA创建了一个图表,我想调整线条颜色和x轴间隔 代码如下: Sub add_cpu_chart(server_hostname, site) On Error Resume Next Dim rpt_site As String rpt_site = site Set tbl = ThisWorkbook.Sheets(server_hostname).ListObjects(1) strTableName = tbl.Name
Sub add_cpu_chart(server_hostname, site)
On Error Resume Next
Dim rpt_site As String
rpt_site = site
Set tbl = ThisWorkbook.Sheets(server_hostname).ListObjects(1)
strTableName = tbl.Name
strTableRange = tbl.Range.Address
Dim m_s_name, m_e_name As Date
m_s_name = CDate(fromDateStr)
m_e_name = CDate(toDateStr)
'Create new embedded chart
Set shp = ThisWorkbook.Sheets(server_hostname).Shapes.AddChart
'Position Shape over range
shp.Top = 100
shp.Left = 200
With shp
With .Chart
'Specify source data and orientation
'.SetSourceData Source:=ActiveSheets.Range(Table1 & "[#All]"), _
'PlotBy:=xlRows
.SetSourceData Source:=ThisWorkbook.Sheets(server_hostname).Range(strTableName & "[#All]")
.ChartType = xlLineMarkers
.SetElement (msoElementChartTitleAboveChart)
.HasTitle = True
.ChartTitle.Text = "CPU Utilization of " & server_hostname & " in " & _
rpt_site & " (" & Format(m_s_name, "dd-Mmm") & " to " & Format(m_e_name, "dd-Mmm yyyy") & ")"
.ChartTitle.Font.Size = 14
'.ChartArea.Font.Size = 14
.Legend.Delete
.SetElement (msoElementPrimaryValueAxisTitleRotated)
.Axes(xlValue, xlPrimary).AxisTitle.Text = "CPU Utlization (%)"
.Axes(xlValue, xlPrimary).AxisTitle.Font.Size = 10
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MinorUnit = 2
.Axes(xlValue).MaximumScale = 100
.Axes(xlValue).MajorUnit = 20
.Axes(xlValue).TickLabels.NumberFormat = "General"
.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
.Axes(xlCategory, xlPrimary).AxisTitle.Text = "Date of the Month"
.Axes(xlCategory, xlPrimary).AxisTitle.Font.Size = 10
'.Axes(xlCategory).MajorUnit = 1
.Axes(xlCategory).TickLabels.NumberFormat = "d"
With .PlotArea.Format.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.150000006
.Transparency = 0
.Solid
End With
End With
End With
End Sub
我想将线条颜色更改为红色-就像在excel 2003中一样-以及更改间隔为2天的数据。目前,数据的格式为
1,2,3,4…
我想以1,3,5…
的格式显示数据。在折线图中,X轴的最小比例、最大比例、主要单位和最小单位都是无意义的。X值只是没有解释数值的类别,即使标签上显示数字
您可能应该更改为XY图表,这将允许使用minimumscale、maximum scale、majorunit和minorunit完全控制轴比例。当然,XY图表允许使用与折线图相同的系列标记和线条格式,但令人困惑的术语将永远存在
如果出于某种原因,您决定坚持使用折线图,您可以使用
ActiveChart.Axes(xlCategory).TickLabelSpacing=2在折线图中,X轴的最小刻度、最大刻度、主单位和最小单位没有意义。X值只是没有解释数值的类别,即使标签上显示数字 您可能应该更改为XY图表,这将允许使用minimumscale、maximum scale、majorunit和minorunit完全控制轴比例。当然,XY图表允许使用与折线图相同的系列标记和线条格式,但令人困惑的术语将永远存在 如果出于某种原因,您决定坚持使用折线图,您可以使用
ActiveChart.Axes(xlCategory).ticklabelspace=2
我想显示1,3,5..
那么你被困在哪里了?你犯了什么错误?虽然我怀疑您在开始时遇到了任何错误,但请继续执行下一步的。删除该行:)@Ivan Chan,如果您找到解决问题的有用解决方案,请将其标记为已接受。否则,人们可能会对以有用的方式回答您的问题犹豫不决。我想展示1、3、5..
那么您被困在哪里?你犯了什么错误?虽然我怀疑您在开始时遇到了任何错误,但请继续执行下一步的。删除该行:)@Ivan Chan,如果您找到解决问题的有用解决方案,请将其标记为已接受。否则,人们可能会犹豫是否以有用的方式回答您的问题。