質問

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
役に立ちましたか?

解決

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])

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top