Ok, so I've got my script. Currently, it correctly plots points, but now I want to connect those points to make a line graph. I've tried a lot of different things, but I've not gotten it right. I think the only problem is that the lines have wrong slopes, but I'm not sure if that's the only problem.
PS: If you know of a script that does exactly what I am describing (plotting points and/or drawing lines), then let me know!
Btw, this script uses the data from this table:
{18.351, 18.615, 18.516, 18.921, 19.012, 19.051}
local x2 = 0
local y2 = 0
local x1 = 0
local y1 = 0
local dist = 0
local slope = 0
local line = 0
function graph(x, y, i)
local p = Instance.new("Frame", script.Parent.Pixels)
p.Size = UDim2.new(0, 5, 0, 5)
p.Position = UDim2.new(x, 0, y, 0)
p.BorderSizePixel = 0
p.BackgroundColor3 = Color3.new(200, 20, 20)
p.Name = p.Name .. i
p.ZIndex = 3
if p.Position.Y.Scale > High then
High = p.Position.Y.Scale
end
if p.Position.Y.Scale < Low then
Low = p.Position.Y.Scale
end
local SpanY = High - Low
local PixelY = p.Position.Y.Scale
local FactorY = High - PixelY
local FractionY = FactorY / SpanY
local PixelX = p.Position.X.Scale
local FactorX = (#bux - 1) - PixelX
local FractionX = FactorX / (#bux - 1)
local XO = p.Position.X.Offset
local YO = p.Position.Y.Offset
p.Position = UDim2.new(FractionX, XO, FractionY, YO)
--ALL THE CODE ABOVE IS JUST TO PLOT THE POINTS
--All THE CODE BELOW IS TO MAKE THE LINES
--So the idea here is to make a new frame, make its height 10 pixels (how thick the line is)
--and make adjust its length using distance formula, then adjust its rotation using slope form
--and convert that to degrees. Then make its position the same position as point 1 (which is the top left of the new line, because it is going to the right). Also, X?, Y?, X?, Y? are found by storing each ? and ? into a variable based on if the loop iteration is even or odd.
if i%2 == 0 then --So it does "every other" to connect both points when it can only look at one at a time
y2 = p.Position.Y.Scale * script.Parent.AbsoluteSize.Y
x2 = p.Position.X.Scale * script.Parent.AbsoluteSize.X
elseif i%2 == 1 then
y1 = p.Position.Y.Scale * script.Parent.AbsoluteSize.Y
x1 = p.Position.X.Scale * script.Parent.AbsoluteSize.X
slope = math.atan2((y2 - y1),(x2 - x1))
dist = math.sqrt(math.pow((x2 - x1), 2) + math.pow((y2 - y1), 2))
line = Instance.new('Frame', script.Parent.Lines)
line.BorderSizePixel = 0
line.Size = UDim2.new(0, dist, 0, 10)
print(slope, slope * 360)
line.Rotation = slope * 360
line.Position = UDim2.new(0, x2, 0, y2)
line.Name = i
end
end
bux = {18.351, 18.615, 18.516, 18.921, 19.012, 19.051} --Not my actual bux/tix data, but random example
for i = #bux-1, 1, -1 do
x = i
y = bux[i]
graph(x, y, i)
end

1 comment
The problem with Rotation scripting is that ROBLOX anchors rotation to the center of the GUI element, but positioning to the top left, unrotated, making it much harder than it has to be to get the math right.