By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

How to plot dymanic pie chart from text file?

P: 16
Hi, is there anyway to make the file reader read the text file dymanic?

Here are the codes.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  // Standard inclusions   
  4.  include("pChart/pData.class");
  5.  include("pChart/pChart.class");
  6.  
  7.      $file = "C:\Log\NMS-Television2011101416.txt"; 
  8.  
  9.   $Tv = count(file($file)); 
  10.  
  11.   echo "$Tv";
  12.   $file = "C:\Log\NMS-Games2011101315.txt"; 
  13.  
  14.   $Games = count(file($file)); 
  15.  
  16.   echo "$Games"; 
  17.  
  18.   $file = "C:\Log\NMS-Film2011101416.txt"; 
  19.  
  20.   $Film = count(file($file)); 
  21.  
  22.   echo "$Film"; 
  23.  
  24.   $file = "C:\Log\NMS-Pulishing2011100714.txt"; 
  25.  
  26.   $Pulishing = count(file($file)); 
  27.  
  28.   echo "$Pulishing"; 
  29.  
  30.    $file = "C:\Log\NMS-Animation2011101116.txt"; 
  31.  
  32.   $Animation = count(file($file)); 
  33.  
  34.   echo "$Animation"; 
  35.  
  36.    $file = "C:\Log\NMS-Distribution_Media_Services2011101014.txt"; 
  37.  
  38.   $Distribution = count(file($file)); 
  39.  
  40.   echo "$Distribution";
  41.  
  42.    $file = "C:\Log\NMS-Broadcasting & Technology2011101315.txt"; 
  43.  
  44.   $Broadcasting = count(file($file)); 
  45.  
  46.   echo "$Broadcasting"; 
  47.  
  48.  // Dataset definition 
  49.  $DataSet = new pData;
  50.  $DataSet->AddPoint(array($Tv,$Games,$Film,$Pulishing,$Animation,$Distribution,$Broadcasting),"Serie1");
  51.  $DataSet->AddPoint(array("Television","Games","Film","Pulishing","Animation","Distribution","Broadcasting"),"Serie2");
  52.  $DataSet->AddAllSeries();
  53.  $DataSet->SetAbsciseLabelSerie("Serie2");
  54.  
  55.  // Initialise the graph
  56.  $Test = new pChart(800,500);
  57.  $Test->drawFilledRoundedRectangle(7,7,413,243,5,240,240,240);
  58.  $Test->drawRoundedRectangle(5,5,415,245,5,230,230,230);
  59.  $Test->createColorGradientPalette(195,204,56,223,110,41,5);
  60.  
  61.  // Draw the pie chart
  62.  $Test->setFontProperties("Fonts/tahoma.ttf",8);
  63.  $Test->AntialiasQuality = 0;
  64.  $Test->drawPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),180,130,110,PIE_PERCENTAGE_LABEL,FALSE,50,20,5);
  65.  $Test->drawPieLegend(400,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250);
  66.  
  67.  // Write the title
  68.  $Test->setFontProperties("Fonts/MankSans.ttf",10);
  69.  $Test->drawTitle(10,20,"Number of View",100,100,100);
  70.  
  71.  $Test->Render("example10.png");
  72. ?>
Oct 28 '11 #1
Share this Question
Share on Google+
12 Replies


100+
P: 1,059
all file reading are dynamic.

What is your problem??
reading the file or creating the pie chart
Oct 30 '11 #2

P: 16
@johny10151981
I want the program to find the file itself. For example, there is many type of files in the folder, sort by date, if i want to call a few file out it will auto be sort into the pie chart.
Oct 31 '11 #3

omerbutt
100+
P: 638
HI SEAN ,
why dont you store the name/path of the file somewhere and retrieve it at the time of reading it .
regards,
Omer Aslam
Nov 2 '11 #4

P: 16
@omerbutt
Those text file is save in a folder but i have no idea how to retrieve it dynamic.
For example, i need a from today and ytd files it will automatically those text file in and generate the chart.
Nov 2 '11 #5

omerbutt
100+
P: 638
weel what i am getting from your reply is that,
the file is saved inside a folder. But is the system saving the file? or the file is saved by some person or you manually? , if the system is saving the file means there is another process that writes the data inside a file and saves it then you need to save the name of the file inside the db and retrieve it later, if i didnt get you right , do correct me .
regards,
Omer Aslam
Nov 2 '11 #6

P: 16
@omerbutt
Yeah you are right, the file is saved inside a folder by a system, it records the number of use of a program per hourly and name the file in YYYYMMDDHH format. It is not acutally a db, a folder rather.

Now i got to do is get those files from the folder based on the file name automatically, for example i want file from 2pm to 6pm, then those file will be place in the code automatically and generate into a pie chart.
Nov 2 '11 #7

omerbutt
100+
P: 638
you need to have some thing to track the filenames as you said you need the file of 2pm to 6pm then why not use the
Expand|Select|Wrap|Line Numbers
  1. filemtime()
  2.  
to track which files were written at the given time
see the manual here

you can even look at the
Expand|Select|Wrap|Line Numbers
  1. filectime()
  2. stat()
  3.  
on the given link
regards,
Omer Aslam
Nov 2 '11 #8

P: 16
@omerbutt
ya i do need to track the files i need and extract it to generate a pie chart.
Nov 2 '11 #9

omerbutt
100+
P: 638
did it worked out for you sean , do ell me when you are done with it , or in case you got some problem
reagrds,
Omer Aslam
Nov 2 '11 #10

P: 16
Ok i am still trying it out, will get back to you tmr. Thanks for the help!
Nov 2 '11 #11

P: 16
Based on what i have learn so far, i still have to hard code in the textfile myself. My requirement doesn't allow me to do that, it will generate file every hour when the program start running.

Correct me if i'm wrong, Thanks.
Nov 3 '11 #12

omerbutt
100+
P: 638
Hi
cant you have a cron job type something that would trigger to save the file name when the file is created?........if its a local computer the you can use scheduler and remote mysql connection to update the live db .......are you getting what i am trying to say ?
regards,
Omer Aslam
Nov 10 '11 #13

Post your reply

Sign in to post your reply or Sign up for a free account.