0

I am trying to create a way so that I can collect 5 points within the (x,y) format. Then, I want to take those points and plot them on a coordinate plane. I am not sure how to write this, espicially when I am only planning on PHP. I have successfully created something like this before but it was made to take an equation yet using Javascript rather than php.

Anyone got any resources for this? I couldn't find anything on this, I even used wolfram's widget builder and didn't achieve success.

Thanks in advance!

3
Contributors
14
Replies
54
Views
3 Years
Discussion Span
Last Post by diafol
Featured Replies
  • 1

    I would say high charts. It has the best documentation and ease of use IMO. Read More

  • 1

    http://www.highcharts.com/ I was looking at flot but I thought the documentation was ridiculously complicated as it is controlled with javascript and it has some issues with lower internet explorer versions. I'm in the process of migrating everything to highcharts - it's free but requires a commercial license for something more … Read More

  • 1
    diafol 3,720   3 Years Ago

    Highcharts is js. There are plenty of php chart scripts. Which ones have you tried? You could even create your own with something like the GD library. Read More

  • 1
    diafol 3,720   3 Years Ago

    Here's something I knocked up in about 10 minutes: class graph { protected $im; protected $height; protected $width; public function setContainer($width, $height, $background) { $this->im = imagecreatetruecolor($width, $height); $this->width = $width; $this->height = $height; $rgbA = $this->hex2rgb($background); $rgb = ImageColorAllocate($this->im,$rgbA[0],$rgbA[1],$rgbA[2]); imagefilledrectangle($this->im, 0, 0, $width, $height, $rgb); } public function addData($set, … Read More

  • 1
    diafol 3,720   3 Years Ago

    Anything over a 100 lines or so and I fall asleep. :( Read More

1

I would say high charts. It has the best documentation and ease of use IMO.

Votes + Comments
thanks for the quick response
0

High Charts? I haven't heard of those, do you know where i can find the documentation/library for it?

1

http://www.highcharts.com/

I was looking at flot but I thought the documentation was ridiculously complicated as it is controlled with javascript and it has some issues with lower internet explorer versions.

I'm in the process of migrating everything to highcharts - it's free but requires a commercial license for something more than personal use.

Votes + Comments
I'll look into it!
0

I am going to look into High Charts but for now, I am going to be leaving this thread open for more ideas/resources.
Thanks!

1

Highcharts is js. There are plenty of php chart scripts. Which ones have you tried? You could even create your own with something like the GD library.

1

Here's something I knocked up in about 10 minutes:

class graph
{

    protected $im;
    protected $height;
    protected $width;

    public function setContainer($width, $height, $background)
    {
        $this->im  = imagecreatetruecolor($width, $height); 
        $this->width = $width;
        $this->height = $height;

        $rgbA = $this->hex2rgb($background);

        $rgb = ImageColorAllocate($this->im,$rgbA[0],$rgbA[1],$rgbA[2]);

        imagefilledrectangle($this->im, 0, 0, $width, $height, $rgb);   
    }

    public function addData($set, $dotDiameter, $dotColour, $lineWidth, $lineColour)
    {
        $dotrgbA = $this->hex2rgb($dotColour);
        $linergbA = $this->hex2rgb($lineColour);

        $dotrgb = imagecolorallocate($this->im, $dotrgbA[0], $dotrgbA[1], $dotrgbA[2]);
        $linergb = imagecolorallocate($this->im, $linergbA[0], $linergbA[1], $linergbA[2]);
        $prev = NULL;
        foreach($set as $datapoints)
        {
            imagefilledellipse($this->im, $datapoints[0], $this->height-$datapoints[1], $dotDiameter, $dotDiameter, $dotrgb);
            if(!is_null($prev))
                imageline($this->im, $prev[0], $this->height-$prev[1], $datapoints[0], $this->height-$datapoints[1], $linergb);
            $prev = $datapoints;
        }
    }

    public function saveAndShow()
    {
        $t = time();
        imagepng($this->im, "img_$t.png");
        imagedestroy($this->im);
        echo "<img src='img_$t.png' />"; 
    }

    private function hex2rgb($hex)
    {
        $int = hexdec($hex);
        return array
                (
                    0xFF & ($int >> 0x10),
                    0xFF & ($int >> 0x8),
                    0xFF & $int
                );  
    }

}

$data = array(
    array(0, 40),
    array(100,78),
    array(200,61),
    array(300,45),
    array(400,24),

);

$g = new graph;
//width,height,background colour
$g->setContainer(400,100,'#FF0099');
//data, dot size, dot colour, line width (not implemented), line colour
$g->addData($data,10,'ffffff',3,'000000');
//save image to current directory (timestamped name png file) and display 
$g->saveAndShow();

That's very rough and ready, but shows what can be done with the GD library with very little effort.

Votes + Comments
You make it sound so easy...
0

Here's something I knocked up in about 10 minutes:

I like how you make it sound so easy. What you wrote takes me an easy 2-3 hours lol. but i will study your snippet of code in about 1 hour because i am outside at the moment.

0

I was exploring the link provided and I am confused on how a coordinate plane would be made... anyone know anything about that if not know if it is on their site?

0

I've not really dug that much into high charts at all to be honest but provide some code and what you are expecting and I may be able to help.

0

@diafol, a coordinate plane as in this

@iamthwee, I have done this (the code is a part of the question, it is kind of long) in javascript but I am not too sure on how to do it in php, unless there is a way a can collect the points and draw them on the plane using javascript rather than php.

0

heh heh 800+ lines. Did anybody respond?

0

heh heh 800+ lines. Did anybody respond?

heh heh nope... -_-
Though a response would be great... even if it says google it lol.

1

Anything over a 100 lines or so and I fall asleep. :(

Votes + Comments
Same here... sorta
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.