我有一个宏,可以从一系列数据中生成Chart
。见下面的数据:
2015/08/01 12:49.002
2015/08/01 00:41.600
2015/08/02 00:27.198
2015/08/03 01:05.600
2015/08/03 01:30.599
2015/08/04 02:29.799
2015/08/05 01:40.199
2015/08/06 01:36.199
2015/08/07 02:16.998
2015/08/07 00:43.401
第一列代表日期,第二列是该日期的时间范围。
注意我在工作表中找到的原始数据是已合并的单元格。有关详细信息,请参阅下面的屏幕截图。
问题是图表只显示为该日期分配的更大数字。
见下面的代码。
Option Explicit
Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Sub CreateChart()
Dim DateRange, TimeRange As Range
Dim lastRow As Long
Dim StartRow As Long, columnIndex As Long
Dim DataWorkSheet As Worksheet
Dim DataFileFullPath As String, DataFileName As String, SheetName As String
Dim Index As Long, Index2 As Long
Dim t As Long
Dim tt As Long
Dim Chart1 As Chart
' 'Disable Screen Updating
' Application.ScreenUpdating = False
' Application.Calculation = xlCalculationManual
StartRow = 20
columnIndex = 3
'Put Full File Path for your demo/test file here
DataFileFullPath = "C:\Users\................."
Index = InStrRev(DataFileFullPath, "\")
DataFileName = Right(DataFileFullPath, Len(DataFileFullPath) - Index)
Index2 = InStrRev(DataFileName, ".")
SheetName = Left(DataFileName, Index2 - 1)
Set DataWorkSheet = Workbooks(DataFileName).Sheets(SheetName)
t = GetTickCount
With DataWorkSheet
With .UsedRange
'Getting the last Row
lastRow = .Rows(.Rows.Count).row - 1
End With
'The DataStartRow is set to the ORiginal Time from the T3000
Set DateRange = .Range(.Cells(StartRow, columnIndex + 1), .Cells(lastRow, columnIndex + 1))
Set TimeRange = .Range(.Cells(StartRow, columnIndex + 2), .Cells(lastRow, columnIndex + 2))
End With
Set Chart1 = Charts.Add
With Chart1
.ChartType = xlColumnClustered
.SeriesCollection.NewSeries
With .SeriesCollection(1)
.Values = TimeRange
.Name = SheetName & " " & "Synch Time"
.XValues = DateRange
End With
.Name = SheetName & " " & "Synch Time Chart"
.Axes(xlValue).MaximumScale = 0.0104166667 ' 15 mins / 50 / 24
.Axes(xlValue).MajorUnit = 0.0006944444 ' 1 mins /60 / 24
.Move After:=Sheets(2)
End With
tt = GetTickCount - t
' 'Enable Screen Updating
' Application.ScreenUpdating = True
' Application.Calculation = xlCalculationAutomatic
End Sub
是否需要包含Chart1
的元素,以便不在特定日期省略第二个数据值?
答案 0 :(得分:1)
如果您想在X轴上重复这一天,则需要添加:
.Axes(xlCategory).CategoryType = xlCategoryScale
答案 1 :(得分:0)
使用@Rory的答案,我看到所有行都显示出来了。
在进行一些搜索后,我在Chart
中看到,默认情况下,Chart
中只显示所显示单元格中的数据(即未隐藏)。
然后我在一个脚本中加入了一个Range(Rows(x), Rows(y)).Hidden = True
,它给了我特定时间段内的合并单元格。
下面的图片代表最终产品。
您可以在图表
中查看2015/08/01的双重条目右键单击轴时,.Axes(xlCategory).CategoryType = xlCategoryScale
基本上将Hosrizontal Axis Type设置为“文本轴”,如Excel弹出菜单中所述
欢迎使用其答案中提到的使用不同类型的图表作为Rory的任何其他建议。
暂时不会回答此问题。