我正在尝试为条形图的 x 轴分配一个标签,该标签是存储在 $gsettings['axisXlabel'] 下的数组中的普通文本字符串。不幸的是 pCharts SetSerieDescription 似乎没有按预期工作。
下面是生成图表的函数和当前输出的附件。感兴趣的部分是 /* 将数据系列绑定到 X 轴下的 3 行 */
/**
* function to plot bar charts
*/
function cg_graphs_plot_bar_graph($gdata, $gsettings){
$graph_data = new pData();
if(isset($gdata['bar_plots2'])){ //if this is set, its a duel bar graph
$graph_data->addPoints($gdata['bar_plots'],"surgeondata");
$graph_data->addPoints(array(0,0,0,0),"surgeondatanull");
$graph_data->addPoints($gdata['bar_plots2'],"everyonedata");
$graph_data->addPoints(array(0,0,0,0),"everyonedatanull");
$graph_data->setSerieDrawable(array("everyonedatanull"), FALSE);
$graph_data->setSerieDescription("surgeondata",$gdata['surgeonname']);
$graph_data->setSerieDescription("everyonedata","All Surgeons");
$graph_data->setAxisUnit(0,"%");
$surgeon = array("R"=>21,"G"=>0,"B"=>0); //surgeon series colour
$all = array("R"=>191,"G"=>160,"B"=>36); //everyone series colour
$graph_data->setPalette("surgeondata",$surgeon);
$graph_data->setPalette("everyonedata",$all);
$graph_data->setPalette("surgeondatanull",$surgeon);
$graph_data->setPalette("everyonedatanull",$all);
} else {
$graph_data->addPoints($gdata['bar_plots'],"percentiles");
$graph_data->addPoints($gdata['surgeon_bar'],"surgeonbar");
$graph_data->setSerieDrawable(array("surgeonbar"), FALSE);
}
$graph_data->setAxisName(0,$gsettings['axisYlabel']);
/* Bind a data serie to the X axis */
$graph_data->addPoints($gdata['xaxis_names'],"Labels");
$graph_data->setSerieDescription("Labels",$gsettings['axisXlabel']);
$graph_data->setAbscissa("Labels");
$width=540;
$height=419;
$chart = new pImage($width,$height,$graph_data);
$chart->drawFromJPG(0,0,drupal_get_path('module', 'cg_graphs')."/images/graphbg.jpg");
/* Write the picture title */
$chart->setFontProperties(array("FontName"=>drupal_get_path('module', 'cg_graphs')."/pChart/fonts/ARIAL.TTF","FontSize"=>8));
$chart->setFontProperties(array("R"=>0,"G"=>0,"B"=>0));
$chart->drawText(270,70,$gsettings['title'],array("R"=>0,"G"=>0,"B"=>0,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE, "FontSize" => 12));
/* Set the graph area */
$chart->setGraphArea(70,120,490,310);
/* Draw a rectangle */
$chart->drawFilledRectangle(70,120,489,309,array("R"=>255,"G"=>255,"B"=>255,"Dash"=>FALSE, "BorderR"=>201,"BorderG"=>201,"BorderB"=>201));
/* Turn on shadow computing */
$chart->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
$format = array(
"DisplayValues"=>FALSE,
"DisplayColor"=>DISPLAY_AUTO,
"Rounded"=>FALSE,
"Gradient"=>TRUE,
"GradientAlpha"=>100,
"GradientMode"=>GRADIENT_EFFECT_CAN,
"GradientStartR"=>251,
"GradientStartG"=>220,
"GradientStartB"=>96,
"GradientEndR"=>191,
"GradientEndG"=>160,
"GradientEndtB"=>36
);
if(isset($gdata['bar_plots2'])){
/* Draw the scale */
$chart->drawScale(array("XMargin"=>50, "Mode"=>SCALE_MODE_MANUAL, "ManualScale"=> $gsettings['maxmin'], "Pos" => SCALE_POS_LEFTRIGHT,'DrawXLines' => FALSE, 'GridTicks' => 500,'GridR'=>0,'GridG'=>0,'GridB'=>0, 'LabelRotation'=>0, 'AroundZero' => TRUE, 'Interleave' => 0.1));
$graph_data->setSerieDrawable(array("surgeondata"), FALSE);
$graph_data->setSerieDrawable(array("surgeondatanull"), TRUE);
} else {
/* Draw the scale*/
$chart->drawScale(array("XMargin"=>40, "Mode"=>SCALE_MODE_MANUAL, "ManualScale"=> $gsettings['maxmin'], "Pos" => SCALE_POS_LEFTRIGHT,'DrawXLines' => FALSE, 'GridTicks' => 500,'GridR'=>0,'GridG'=>0,'GridB'=>0, 'LabelRotation'=>0, 'AroundZero' => TRUE));
}
$chart->drawBarChart($format);
//draw next bar with new colour.
$format = array(
"DisplayValues"=>FALSE,
"DisplayColor"=>DISPLAY_AUTO,
"Rounded"=>FALSE,
"Gradient"=>TRUE,
"GradientAlpha"=>100,
"GradientMode"=>GRADIENT_EFFECT_CAN,
"GradientStartR"=>255,
"GradientStartG"=>230,
"GradientStartB"=>126,
"GradientEndR"=>21,
"GradientEndG"=>0,
"GradientEndtB"=>0
);
if(!isset($gdata['bar_plots2'])){ //not set? we need to draw the second one.
//set draw series to false / true here
$graph_data->setSerieDrawable(array("percentiles"), FALSE);
$graph_data->setSerieDrawable(array("surgeonbar"), TRUE);
$chart->drawBarChart($format);
} else {
$graph_data->setSerieDrawable(array("surgeondatanull", "everyonedata"), FALSE);
$graph_data->setSerieDrawable(array("surgeondata", "everyonedatanull"), TRUE);
$chart->drawBarChart($format);
$graph_data->setSerieDrawable(array("everyonedatanull"), FALSE);
$graph_data->setSerieDrawable(array("everyonedata"), TRUE);
$chart->drawLegend(190,100,array("Style"=>LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); //draw legand
}
$imagename = str_replace(' ', '-', $gdata['surgeonname']);
$chart->render(drupal_get_path('module', 'cg_graphs')."/pChart/examples/pictures/".$imagename."-".$gsettings['name'].".png");
}
这是输出,我想给 Xaxis 加上标签,目前标签没有显示。(抱歉删除了标题等,数据尚未进入公共领域,需要删除名称)