So I have the script below, where p = Instance.new('Frame', Lines) and this is all held within a for loop, so p2 is essentially the previous p Frame, so that it can be referred to when getting the points to draw between when drawing the line.
if i%2 == 0 then
local VD = math.abs(p.Position.Y.Scale - p2.Position.Y.Scale) --Verticle Distance, I tried magnitude but couldn't get it to work
local HD = math.abs(p.Position.X.Scale - p2.Position.X.Scale) --Horizontal Distance
local DD = math.sqrt(HD^2 + VD^2) --Diagonal Distance
local DR = math.atan(VD/HD) --Diagonal Rotation
print("VD: ", VD, ", HD: ", HD, ", DD: ", DD, ", DR: ", DR)
local l = Instance.new('Frame', Lines)
l.Size = UDim2.new(DD, 0, 0, 1)
l.Rotation = DR
l.Position = UDim2.new(p2.Position.X.Scale, 0, p2.Position.Y.Scale, 0)
end
p2 = p
Here is what the output looks like: https://gyazo.com/5dbd3237294267dca9aa552050c27a8e https://gyazo.com/e57ea82a2e9e925257cc7f308f6afe9f
I tried following this equation for the rotation of the line:
Slope Angle = Arctan(VD/HD)
I tried following this equation for the length of the line:
?(x2-x1)2+(y2-y1)^2
And I positioned it to p2 (since positioning is based on the top-left corner)
EDIT 1: I now realize that positioning to p2 isn't right, but that doesn't account for the wacky lines.
EDIT 2: So here is the data I'm trying to graph:
http://tcserver.raspctl.com/tc/r/10000/all.txt
It looks like this in case you can't reach the server:
18.189,18.282,18.282,18.285,18.271,18.277,18.275
I already have a function that properly splits it by its commas, so that is not a problem.
The x-axis can just be graphed like 1,2,3,etc.
So here is my full script:
Pixels = script.Parent.Pixels
Lines = script.Parent.Lines
GuiStorage = game.ServerStorage.GuiStorage
function explode(d, p)
local t, ll
t = {}
ll= 0
if(#p == 1) then return {p} end
while true do
local l = string.find(p, d, ll, true) --find the next d in the string
if l ~= nil then --if "not not" found then..
table.insert(t, tonumber(string.sub(p, ll, l - 1))) --Save it in our array.
ll = l + 1 --save just after where we found it for searching next time.
else
table.insert(t, tonumber(string.sub(p, ll))) --Save what's left in our array.
break --Break at end, as it should be, according to the lua manual.
end
end
return t
end
function getLineBetweenPointFrames(p1, p2, lineFrame, parentGui)
-- Syntax sugar
local p1X, p1Y = p1[1], p1[2]
local p2X, p2Y = p2[1], p2[2]
-- Get X and Y components of the line length
local lenX = math.abs(p2X - p1X)
local lenY = math.abs(p2Y - p1Y)
-- Get diagonal (true) line length
local lenD = math.sqrt(math.pow(lenX,2) + math.pow(lenY,2))
-- Find X and Y coordinates for line's position
local nX = (p1X < p2X and p1X or p2X) + lenX / 2 - lenD / 2
local nY = (p1Y < p2Y and p1Y or p2Y) + lenY / 2
-- Find the rotation of the line
local rot = math.deg(math.atan2(lenY, lenX))
-- Flip the rotation if needed
local X1Start = p1X < p2X
local Y1Start = p1Y < p2Y
if (X1Start and not Y1Start) or (not X1Start and Y1Start) then -- Some Boolean logic
rot = 180 - rot
end
-- Create a line Frame with calculated properties
local line = lineFrame:Clone()
line.Parent = parentGui
line.Position = UDim2.new(0, nX, 0, nY)
line.Size = UDim2.new(0, lenD, 0, 3)
line.Rotation = rot
return line
end
function graph(data, type)
local datamax = math.max(unpack(data))
local datamin = math.min(unpack(data))
local SpanY = datamax - datamin
for i = 1, #data do
local PixelY = data[i]
local SpanPixelY = datamax - PixelY
local FractionY = SpanPixelY / SpanY
local PixelX = i
local SpanPixelX = #data - PixelX
local FractionX = SpanPixelX / #data
p = {FractionX*script.Parent.AbsoluteSize.X, FractionY*script.Parent.AbsoluteSize.Y}
if i%2 == 0 then
if type == "r" then
print("Round ",i," P: ",p[1],":",p[2],"P2: ",p2[1],":",p2[2])
getLineBetweenPointFrames(p, p2, GuiStorage.BuxLine, Lines.Bux)
elseif type == "t" then
print("Round ",i," P: ",p[1],":",p[2],"P2: ",p2[1],":",p2[2])
getLineBetweenPointFrames(p, p2, GuiStorage.TixLine, Lines.Tix)
end
end
p2 = p
end
end
if game.ServerStorage.Local.Value == false then
print('Server IP: WAN')
bux = game:GetService("HttpService"):GetAsync("http://tcserver.raspctl.com/tc/r/1000/7.txt", true)
tix = game:GetService("HttpService"):GetAsync("http://tcserver.raspctl.com/tc/t/1000/7.txt", true)
else
print('Server IP: LAN')
bux = game:GetService("HttpService"):GetAsync("http://10.0.0.21/tc/r/1000/7.txt", true)
tix = game:GetService("HttpService"):GetAsync("http://10.0.0.21/tc/t/1000/7.txt", true)
end
bux = explode(",", bux)
tix = explode(",", tix)
graph(bux, "r")
graph(tix, "t")
print("Getting Max/Min...")
print("Max Bux: ", math.max(unpack(bux)), "Min Bux: ", math.min(unpack(bux)))
print("Max Tix: ", math.max(unpack(tix)), "Min Tix: ", math.min(unpack(tix)))

4 comments
For some reason, this partly draws the line. Here is a GIF of what the line looks like: https://gyazo.com/c436c323a6cf55b44d2a477efc7562df
Are you sure you have the point Frames set up correctly? They have to be a gui object with size 1,1, btw. I tested the function and it worked fine for me.
I've tried using your function alone in a script, and it worked fine. But when I run it in my loop, passing in p and p2, it does that. I'll try to find what is wrong.
I tried using the raw data instead of adjusting for the scale of the graph, but that gave worse results. I've updated my question with the data I'm trying to graph, so if you would have any idea on how to do this.