Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:23:06+00:00 2026-06-13T01:23:06+00:00

I am trying to read Data from a text file and then plot it

  • 0

I am trying to read Data from a text file and then plot it usint PHPplot.
Text file looks like this:

0   24
1   28
2   30
3   35
4   40

I am trying to convert the data into something like:

array(array(0,24),array(1,28),array(2,30),array(3,35),array(4,40))

my code in php is like this

 $file = fopen("data2.txt", "r");;
            while (!feof($file)) {
                $line_of_text .= fgets($file);
            }
            $members = explode("\n", $line_of_text);
            fclose($file);

for ($j=0; $j<=10; $j++)
  {       
  $parts[$j]=explode("   ", $members[$j]);       
  }
# plot 
require_once 'phplot.php';
    for ($x = 0; $x <= 5; $x += 1)
      $data[] = array('', $parts[$x][0], $parts[$x][1]);
    $plot = new PHPlot(800, 600);
    $plot->SetPrintImage(False); // No automatic output
    $plot->SetImageBorderType('plain');
    $plot->SetPlotType('lines');
    $plot->SetDataType('data-data');
    $plot->SetDataValues($data);
    $plot->SetPlotAreaWorld(0, 0, 10, 40);
    $plot->SetDrawYGrid(True);
    $plot->DrawGraph();

the problem is in line:

$data[] = array('', $parts[$x][0], $parts[$x][1]);

that it does not draw the $parts[$x][1] numbers. when I say print $parts[$x][1] values it prints it on the browser but just do not plot it. the interesting part is that when I ask it to plot

$data[] = array('', $parts[$x][0], $parts[$x][1]);

It Plots this time!!

var_dump($parts) gave:

array(11) { [0]=> array(2) { [0]=> string(1) "0" [1]=> string(3) "24 " } [1]=> array(2) { [0]=> string(1) "1" [1]=> string(3) "28 " } [2]=> array(2) { [0]=> string(1) "2" [1]=> string(3) "30 " } [3]=> array(2) { [0]=> string(1) "3" [1]=> string(3) "35 " } [4]=> array(2) { [0]=> string(1) "4" [1]=> string(2) "40" } [5]=> array(1) { [0]=> string(0) "" } [6]=> array(1) { [0]=> string(0) "" } [7]=> array(1) { [0]=> string(0) "" } [8]=> array(1) { [0]=> string(0) "" } [9]=> array(1) { [0]=> string(0) "" } [10]=> array(1) { [0]=> string(0) "" } }

also var_dump($data) gave:

array(5) { [0]=> array(3) { [0]=> string(0) "" [1]=> int(0) [2]=> string(3) "24 " } [1]=> array(3) { [0]=> string(0) "" [1]=> int(1) [2]=> string(3) "28 " } [2]=> array(3) { [0]=> string(0) "" [1]=> int(2) [2]=> string(3) "30 " } [3]=> array(3) { [0]=> string(0) "" [1]=> int(3) [2]=> string(3) "35 " } [4]=> array(3) { [0]=> string(0) "" [1]=> int(4) [2]=> string(2) "40" } }

please help me thanks alot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:23:08+00:00Added an answer on June 13, 2026 at 1:23 am

    Reza, per your vardump, the values in your array are strings and the array you showed in your question had ints. Here is one way to convert these strings to ints.

        for ($j=0; $j<=10; $j++){
            $tmp=explode("   ", $members[$j]);
            for($k=0; $k<count($tmp); $k++){
                $tmp[$k] = intval($tmp[$k]);
            }
            $parts[$j]=$tmp;     
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read data from a text file, clear it, and then write
I'm trying to read data from a binary file and put it into a
I'm trying to read data from a text file and assign it to arrays.
I am trying to read in data from a text file (the time). and
I'm trying to read data from an xml file and display it in a
I am trying to read data from a file stream as shown below: fileStream.Read(byteArray,
I am trying to use a textreader to retrieve data from a text file
I am trying to read in a text file from an SQL query (SQL
I am trying to do the following: Read a text file containing integer data
I'm trying to read the contents of a text file into the attributes of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.