tilpasse grafens udseende via VBA
Jeg vil gerne indsætte axenavne og tittel på min graf som danne via nedenstående VBA-kode (udsnit)Af en eller anden grund går det galt i linien:
myChart.SetSourceData Source:=ws.Range(ws.Cells(1, 1), ws.Cells(1000, 1))
Hvad skyldes det?
Sub GenerateSkewedDistributionChart()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1") ' Husk at tilpasse fanenavn
Dim i As Long
Dim skewVal As Double
Dim mean As Double
Dim stdDev As Double
' Parameters for distribution
mean = 1000 ' Mean of the distribution
stdDev = 50 ' Standard deviation of the distribution
skewVal = 0 ' Adjust the skewness here
' Generate skewed distribution data
For i = 1 To 1000 ' ændre antal til det ønskede
ws.Cells(i, 1).Value = GetSkewedRandomNumber(mean, stdDev, skewVal)
Next i
' laver grafen
Dim myChart As Chart
Set myChart = ws.Shapes.AddChart2(200, xlHistogram, Left:=100, Width:=500, Top:=50, Height:=225).Chart
myChart.SetSourceData Source:=ws.Range(ws.Cells(1, 1), ws.Cells(1000, 1))
With Chart.myChart
.SetSourceData Source:=DataRange
.ChartType = xlColumnClustered
.HasTitle = True
.ChartTitle.Text = "Normal Distribution"
.Axes(xlCategory).HasTitle = True
.Axes(xlCategory).AxisTitle.Text = "Data Points"
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Text = "Frequency"
End With
'myChart.SetSourceData Source:=ws.Range(ws.Cells(1, 1), ws.Cells(1000, 1))
' tilpasse grafens udeeende
' ...
End Sub