There isn't any way (in PHPlot, or PHP/GD for that matter) to switch fonts in
the middle of a string. The way to do what you want in PHPlot is using a
drawing callback to draw 2 strings, one in a normal font, and one in bold,
lined up so they appear to be a single line of text. It isn't that hard, but
only you can decide if it is worth it for your application. Here is a simple
example. It does not attempt to center the text or position it relative to the
top of the plot (taking into account the font size). These are also possible,
but more work.
<?phprequire_once'phplot.php';define('FONT_NORMAL','LiberationSans-Regular.ttf');// System dependentdefine('FONT_BOLD','LiberationSans-Bold.ttf');// System dependent// Drawing callback function:functionadd_title($img,$title){$black=imagecolorresolve($img,0,0,0);$x=20;$y=40;$bbox=imagettftext($img,12,0,$x,$y,$black,FONT_NORMAL,$title[0]);$x+=$bbox[2]-$bbox[0];// Skip past width of first partimagettftext($img,12,0,$x,$y,$black,FONT_BOLD,$title[1]);}$data=array(array('A',1),array('B',2),array('C',3));$p=newPHPlot(800,600);$p->SetDataType('text-data');$p->SetDataValues($data);$p->SetMarginsPixels(NULL,NULL,60);// Leave room at top for special title$p->SetPlotType('bars');$p->SetCallback('draw_all','add_title',array('Plain Text ','Bold Text'));$p->DrawGraph();
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In this application ( graphbarometer.com ), is it possible to make the
$pressure value at the end of the title Bold?
$title = $y . " Current " . $pressure;
Thanks Gary
There isn't any way (in PHPlot, or PHP/GD for that matter) to switch fonts in
the middle of a string. The way to do what you want in PHPlot is using a
drawing callback to draw 2 strings, one in a normal font, and one in bold,
lined up so they appear to be a single line of text. It isn't that hard, but
only you can decide if it is worth it for your application. Here is a simple
example. It does not attempt to center the text or position it relative to the
top of the plot (taking into account the font size). These are also possible,
but more work.
OK thanks lbayuk, I'll work with it but it's probably a bit much for me.