jpgraph 根据其值为每个条形图不同的颜色
jpgraph different color for each bar based on its value
我是 jpgraph 的新手,我有一个条形图,我希望它根据每个条的值具有不同的颜色,
所以在百分比的情况下,当条值是 < 80
时,我希望它是 红色条 ,当它是 >= 80 && <85
时bw 一个 黄色条 当它是 >= 85
一个 绿色条
我所能做的就是为图中的所有条形图赋予相似的颜色
这是代码,如果你能帮我添加条件格式,请帮忙!
$datay=array(90,82,70,30,100,85);
// Create the graph. These two calls are always required
$graph = new Graph(300,200,"auto");
$graph->SetScale("textlin");
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);
// Create a bar pot
$bplot = new BarPlot($datay);
// Adjust fill color
$graph->Add($bplot);
$bplot->value->Show();
/* I tried to add if statement here but the pic won't render */
$bplot->SetFillColor('orange');
// Display the graph
$graph->Stroke();
您可以将每个条形的颜色放在一个数组中,并通过检查每个数据值来分配所需的颜色:
$datay=array(90,82,70,30,100,85);
$barcolors = array();
// Create the graph. These two calls are always required
$graph = new Graph(300,200,"auto");
$graph->SetScale("textlin");
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);
// Create a bar pot
$bplot = new BarPlot($datay);
// Adjust fill color
$graph->Add($bplot);
$bplot->value->Show();
foreach ($datay as $datayvalue) {
if ($datayvalue < '80') $barcolors[]='red';
elseif ($datayvalue >= '80' && $datayvalue < '85') $barcolors[]='yellow';
elseif ($datayvalue >= '85') $barcolors[]='green';
}
$bplot->SetFillColor($barcolors);
// Display the graph
$graph->Stroke();
我是 jpgraph 的新手,我有一个条形图,我希望它根据每个条的值具有不同的颜色,
所以在百分比的情况下,当条值是 < 80
时,我希望它是 红色条 ,当它是 >= 80 && <85
时bw 一个 黄色条 当它是 >= 85
一个 绿色条
我所能做的就是为图中的所有条形图赋予相似的颜色
这是代码,如果你能帮我添加条件格式,请帮忙!
$datay=array(90,82,70,30,100,85);
// Create the graph. These two calls are always required
$graph = new Graph(300,200,"auto");
$graph->SetScale("textlin");
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);
// Create a bar pot
$bplot = new BarPlot($datay);
// Adjust fill color
$graph->Add($bplot);
$bplot->value->Show();
/* I tried to add if statement here but the pic won't render */
$bplot->SetFillColor('orange');
// Display the graph
$graph->Stroke();
您可以将每个条形的颜色放在一个数组中,并通过检查每个数据值来分配所需的颜色:
$datay=array(90,82,70,30,100,85);
$barcolors = array();
// Create the graph. These two calls are always required
$graph = new Graph(300,200,"auto");
$graph->SetScale("textlin");
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);
// Create a bar pot
$bplot = new BarPlot($datay);
// Adjust fill color
$graph->Add($bplot);
$bplot->value->Show();
foreach ($datay as $datayvalue) {
if ($datayvalue < '80') $barcolors[]='red';
elseif ($datayvalue >= '80' && $datayvalue < '85') $barcolors[]='yellow';
elseif ($datayvalue >= '85') $barcolors[]='green';
}
$bplot->SetFillColor($barcolors);
// Display the graph
$graph->Stroke();