Jpgraph不会更改我的barplot上的颜色 [英] Jpgraph wont change colors on my barplot
问题描述
我刚刚开始尝试制作jpgraph和XAMPP. 当我在网上阅读一些文章时,它说您可以将一组颜色传递给setfillcolor,以便每个条形都是不同的颜色.但是,每当我通过它的颜色时,图形就不会从其默认的浅蓝色更改.
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.
图形响应s更改数据,但不更改颜色. 我尝试了一个累积的条形图示例,它似乎对颜色敏感.
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.
我不确定如何诊断这样的问题.请帮忙!
I'm not sure how to diagnose a problem like this. Help please!
下面的代码(Jpgraph文档中的示例,其颜色从橙色更改为#B0C4DE [原始示例中的橙色未显示):
Code Below(Example from the Jpgraph documentation with color changed from orange to #B0C4DE [orange from the original example doesn't show up]):
<?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->SetScale('textlin');
// Rotate graph 90 degrees and set margin
$graph->Set90AndMargin(50,20,50,30);
// Nice shadow
$graph->SetShadow();
// Setup title
$graph->title->Set('Horizontal bar graph ex 1');
$graph->title->SetFont(FF_VERDANA,FS_BOLD,14);
// Setup X-axis
$graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,12);
// Some extra margin looks nicer
$graph->xaxis->SetLabelMargin(10);
// Label align for X-axis
$graph->xaxis->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->yaxis->scale->SetGrace(20);
// We don't want to display Y-axis
$graph->yaxis->Hide();
// Now create a bar pot
$bplot = new BarPlot($datay);
$bplot->SetFillColor("#B0C4DE");
// ALSO tried:
// $bplot->SetColor(array("red","green","blue","gray"));
$bplot->SetShadow();
//You can change the width of the bars if you like
//$bplot->SetWidth(0.5);
// We want to display the value of each bar at the top
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_BOLD,12);
$bplot->value->SetAlign('left','center');
$bplot->value->SetColor('black','darkred');
$bplot->value->SetFormat('%.1f mkr');
// Add the bar to the graph
$graph->Add($bplot);
// .. and stroke the graph
$graph->Stroke();
?>
推荐答案
我遇到了同样的问题,我发现的解决方案是在BarPlot类初始化后定义格式
I had the same problem, the solution I found is to define the formatting after the BarPlot class initialization
$bplot = new BarPlot($datay);
$graph->Add($bplot);
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_BOLD,12);
$bplot->value->SetAlign('left','center');
$bplot->value->SetColor('black','darkred');
$bplot->value->SetFormat('%.1f mkr');
这篇关于Jpgraph不会更改我的barplot上的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!