fork download
  1. Sub sort(x(), y(), n)
  2. For i = 0 To n - 1
  3. For j = 1 To n - i
  4. If x(j - 1) > x(j) Then
  5. t = x(j - 1)
  6. x(j - 1) = x(j)
  7. x(j) = t
  8. t = y(j - 1)
  9. y(j - 1) = y(j)
  10. y(j) = t
  11. End If
  12. Next j
  13. Next i
  14. End Sub
  15.  
  16. Sub test_plot()
  17.  
  18. '適当なデータを用意
  19. Dim x1(5), y1(5)
  20. Dim x2(14), y2(14)
  21.  
  22. For i = 0 To 5
  23. x1(i) = Rnd
  24. y1(i) = x1(i) * x1(i)
  25. Next i
  26. Call sort(x1, y1, 5)
  27.  
  28. For i = 0 To 14
  29. x2(i) = Rnd
  30. y2(i) = x2(i) * x2(i)
  31. Next i
  32. Call sort(x2, y2, 14)
  33.  
  34. '確認のためにセルに書き込み
  35. [A1] = "x1"
  36. [B1] = "y1"
  37. For i = 0 To 5
  38. Cells(2 + i, 1) = x1(i)
  39. Cells(2 + i, 2) = y1(i)
  40. Next i
  41.  
  42. [C1] = "x2"
  43. [D1] = "y2"
  44. For i = 0 To 14
  45. Cells(2 + i, 3) = x2(i)
  46. Cells(2 + i, 4) = y2(i)
  47. Next i
  48.  
  49. 'グラフ描画
  50. Dim ch As ChartObject
  51. Set ch = ActiveSheet.ChartObjects.Add(300, 10, 300, 200)
  52.  
  53. With ch.chart
  54. 'データ系列の設定
  55. With .SeriesCollection.NewSeries
  56. .ChartType = xlXYScatter
  57. .AxisGroup = xlPrimary
  58. .XValues = x1
  59. .Values = y1
  60. End With
  61.  
  62. With .SeriesCollection.NewSeries
  63. .ChartType = xlXYScatterLinesNoMarkers
  64. .AxisGroup = xlSecondary
  65. .XValues = x2
  66. .Values = y2
  67. End With
  68.  
  69. 'それぞれの軸の設定
  70. With .Axes(xlCategory, xlPrimary)
  71. .HasTitle = True
  72. .AxisTitle.Caption = "x1"
  73. .MinimumScale = 0
  74. .MaximumScale = 1
  75. End With
  76.  
  77. With .Axes(xlCategory, xlSecondary)
  78. .HasTitle = True
  79. .AxisTitle.Caption = "x2"
  80. .MinimumScale = 0
  81. .MaximumScale = 1
  82. End With
  83.  
  84. With .Axes(xlValue, xlPrimary)
  85. .HasTitle = True
  86. .AxisTitle.Caption = "y1"
  87. .MinimumScale = 0
  88. .MaximumScale = 1
  89. End With
  90.  
  91. With .Axes(xlValue, xlSecondary)
  92. .HasTitle = True
  93. .AxisTitle.Caption = "y2"
  94. .MinimumScale = 0
  95. .MaximumScale = 1
  96. End With
  97.  
  98. .HasAxis(xlCategory, xlSecondary) = True
  99.  
  100. End With
  101.  
  102. End Sub
  103.  
  104.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty