I’m trying to create a graph, with dots and lines. Got the dots done, but can’t get the lines connecting them figured out.
local function CreateGraph()
local Size = Graph.Dates.UIListLayout.Padding.Offset
-- Create dots
for i = 1, 7 do
local NewDot = DotTemplate:Clone()
NewDot.Name = "Dot"
NewDot.Position = UDim2.new(0.5, 0, Rates[i] / MAX, 0)
NewDot.Parent = Graph.Dates[i]
end
-- Create lines
for i = 1, 7 do
local Line1 = Graph.Dates:FindFirstChild(i)
local Line2 = Graph.Dates:FindFirstChild(i + 1)
if not Line1 or not Line2 then continue end
local NewLine = LineTemplate:Clone()
local XLength = Line1.Dot.AbsolutePosition.X - Line2.Dot.AbsolutePosition.X
local YLength = Line1.Dot.AbsolutePosition.Y - Line2.Dot.AbsolutePosition.Y
local Mag = (
Vector2.new(Line1.Dot.AbsolutePosition.X, Line1.Dot.AbsolutePosition.Y)
- Vector2.new(Line2.Dot.AbsolutePosition.X, Line2.Dot.AbsolutePosition.Y)
)
local CenterPosition = (Line2.AbsolutePosition + Line1.AbsolutePosition) / 2
NewLine.Rotation = math.atan2(YLength, XLength) * 180 / math.pi
NewLine.Position = UDim2.new(
0,
CenterPosition.X,
0,
CenterPosition.Y
)
NewLine.Size = UDim2.fromOffset(Mag.Magnitude, 4)
NewLine.Parent = Graph.Lines
end
end
It ends up creating the lines on the bottom left of the screen