Excel Graph Automatic Resizing of Axis Origin

社会主义新天地 提交于 2019-12-24 01:04:47

问题


I have the following code which plots a scatter plot. Is there an elegant way to resize the plot area such that the x and y axis do not always automatically start from zero, but rather just below the lowest value? At the moment all my data points end up bunched up in one corner. Many thanks!

Set cht = ActiveChart
'GRAPH 1
    Set rng1 = ActiveSheet.Range(Range("AC13").Offset(jump * 50, 0), Range("AG23").Offset(jump * 50, 0))

With ActiveSheet.ChartObjects.Add(Left:=rng1.Left, Width:=rng1.Width, Top:=rng1.Top, Height:=rng1.Height)
 '(Left:=100, Width:=375, Top:=75, Height:=225)
    .Chart.ChartType = xlXYScatterLines
    .Chart.HasLegend = False
    .Chart.Axes(xlCategory).TickLabels.Font.Size = 18
    .Chart.Axes(xlValue).TickLabels.Font.Size = 18
    '.Chart.SetSourceData Source:=Range("U13:O40,T13:N40")
    Set srs = .Chart.SeriesCollection.NewSeries
            srs.XValues = Range(Range("U13").Offset(jump * 50, 0), Range("U13").Offset(jump * 50, 0).End(xlDown))
    srs.Values = Range(Range("T13").Offset(jump * 50, 0), Range("T13").Offset(jump * 50, 0).End(xlDown))

End With

回答1:


If your y-range data was in cells B1:B10 of the ActiveSheet then you could use code like this to start the range at 90% of the lowest value (ie just below)

Set cht = ActiveChart
cht.Axes(xlValue).MinimumScale = 0.9 * Application.Min([b1:b10])



回答2:


Take a look at this tutorial: Calculate Nice Axis Scales in Excel VBA



来源:https://stackoverflow.com/questions/16211902/excel-graph-automatic-resizing-of-axis-origin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!