Note that there are some explanatory texts on larger screens.

plurals
  1. POJpgraph wont change colors on my barplot
    text
    copied!<p>I'm just getting started with jpgraph and XAMPP I was looking to make a barplot. As I was reading some articles on the web it said you could pass in an array of colors to setfillcolor so that each bar would be a different color. However whenever I pass it color the graph won't change from its default color of light blue.</p> <p>The graph respond s to changes in data but not changes to color. I tried with an accumulated bar graph example and that seems to be color responsive.</p> <p>I'm not sure how to diagnose a problem like this. Help please!</p> <p>Code Below(Example from the Jpgraph documentation with color changed from orange to #B0C4DE [orange from the original example doesn't show up]):</p> <pre><code>&lt;?php // content="text/plain; charset=utf-8" require_once(dirname(__FILE__)."\lib\jpgraph-3.5.0b1\src\jpgraph.php"); require_once(dirname(__FILE__)."\lib\jpgraph-3.5.0b1\src\jpgraph_line.php"); require_once(dirname(__FILE__)."\lib\jpgraph-3.5.0b1\src\jpgraph_bar.php"); $datay=array(2,3,5,25,15,6,3); $datax=array('Jan','Feb','Mar','Apr','May','Jun','Jul'); // Size of graph $width=400; $height=500; // Set the basic parameters of the graph $graph = new Graph($width,$height,'auto'); $graph-&gt;SetScale('textlin'); // Rotate graph 90 degrees and set margin $graph-&gt;Set90AndMargin(50,20,50,30); // Nice shadow $graph-&gt;SetShadow(); // Setup title $graph-&gt;title-&gt;Set('Horizontal bar graph ex 1'); $graph-&gt;title-&gt;SetFont(FF_VERDANA,FS_BOLD,14); // Setup X-axis $graph-&gt;xaxis-&gt;SetTickLabels($datax); $graph-&gt;xaxis-&gt;SetFont(FF_VERDANA,FS_NORMAL,12); // Some extra margin looks nicer $graph-&gt;xaxis-&gt;SetLabelMargin(10); // Label align for X-axis $graph-&gt;xaxis-&gt;SetLabelAlign('right','center'); // Add some grace to y-axis so the bars doesn't go // all the way to the end of the plot area $graph-&gt;yaxis-&gt;scale-&gt;SetGrace(20); // We don't want to display Y-axis $graph-&gt;yaxis-&gt;Hide(); // Now create a bar pot $bplot = new BarPlot($datay); $bplot-&gt;SetFillColor("#B0C4DE"); // ALSO tried: // $bplot-&gt;SetColor(array("red","green","blue","gray")); $bplot-&gt;SetShadow(); //You can change the width of the bars if you like //$bplot-&gt;SetWidth(0.5); // We want to display the value of each bar at the top $bplot-&gt;value-&gt;Show(); $bplot-&gt;value-&gt;SetFont(FF_ARIAL,FS_BOLD,12); $bplot-&gt;value-&gt;SetAlign('left','center'); $bplot-&gt;value-&gt;SetColor('black','darkred'); $bplot-&gt;value-&gt;SetFormat('%.1f mkr'); // Add the bar to the graph $graph-&gt;Add($bplot); // .. and stroke the graph $graph-&gt;Stroke(); ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload