PHP Classes

Specifying x axis text

Recommend this page to a friend!

      Graph Drawing Class 2  >  All threads  >  Specifying x axis text  >  (Un) Subscribe thread alerts  
Subject:Specifying x axis text
Summary:This patch allows you to use the keys in the x_data as labels
Messages:1
Author:Nigel Sim
Date:2007-01-06 10:43:31
 

  1. Specifying x axis text   Reply   Report abuse  
Picture of Nigel Sim Nigel Sim - 2007-01-06 10:43:31
This patch will allow you to use the keys in the x_data array to specify the x-axis text.

ie
$line->x_data = array("A"=>1, "B"=>4);


--- /home/nigel/Desktop/Downloads/graph.php 2007-01-06 20:40:21.000000000 +1000
+++ graph.php 2007-01-06 20:25:52.000000000 +1000
@@ -276,11 +276,11 @@
$fromY = 'none';

//print "set $set<BR>";
//expand_pre($this->calculated['y_plot']);
-
- foreach ($this->x_data as $index => $x) {
-
+ $index = -1;
+ foreach ($this->x_data as $x) {
+ $index++;

//print "index $index<BR>";
$thisY = $this->calculated['y_plot'][$set][$index];
$thisX = $this->calculated['x_plot'][$index];
@@ -720,9 +720,11 @@
$this->calculated['num_bars']++;
}

// calculate y coords for plotting data
- foreach ($this->x_data as $index => $x) {
+ $index = -1;
+ foreach ($this->x_data as $x) {
+ $index++;
$this->calculated['y_plot'][$set][$index] = $this->y_data[$set][$index];

if ((string)$this->y_data[$set][$index] != 'none') {

@@ -1058,17 +1060,19 @@
if ($this->parameter['x_axis_gridlines'] == 'auto') { // auto means text based x_axis, not numeric...
$this->calculated['x_axis']['num_ticks'] = sizeof($this->x_data);
$data = $this->x_data;
for ($i=0; $i < $this->calculated['x_axis']['num_ticks']; $i++) {
+ $key = key($data);
$value = array_shift($data); // grab value from begin of array
+ if (is_numeric($key)) $key = $value;
$this->calculated['x_axis']['data'][$i] = $value;
- $this->calculated['x_axis']['text'][$i] = $value; // raw data and text are both the same in this case
+ $this->calculated['x_axis']['text'][$i] = $key; // raw data and text are both the same in this case
$size = $this->get_boundaryBox(
array('points' => $axis_size,
'font' => $axis_font,
'angle' => $axis_angle,
'colour' => $axis_colour,
- 'text' => $value));
+ 'text' => $key));
$this->calculated['x_axis']['boundary_box'][$i] = $size;
if ($size['height'] > $this->calculated['x_axis']['boundary_box_max']['height'])
$this->calculated['x_axis']['boundary_box_max'] = $size;
}
@@ -1698,5 +1702,5 @@

} // class graph


-?>
\ No newline at end of file
+?>