Jpgraph不会改变barplot上的颜色



我刚刚开始使用jpgraph和XAMPP,我想制作一个barplot。当我在网上读到一些文章时,它说你可以传入一个颜色数组来setfillcolor,这样每个条就会是不同的颜色。然而,无论何时我给它传递颜色,图形都不会改变它的默认颜色浅蓝色。

图形响应数据的变化,但不响应颜色的变化。我尝试了一个累积条形图的例子,这似乎是颜色响应。

我不知道如何诊断这样的问题。请帮助!

下面的代码(来自Jpgraph文档的示例,颜色从橙色更改为#B0C4DE[原始示例的橙色不显示]):

<?php // content="text/plain; charset=utf-8"
require_once(dirname(__FILE__)."libjpgraph-3.5.0b1srcjpgraph.php");
require_once(dirname(__FILE__)."libjpgraph-3.5.0b1srcjpgraph_line.php");
require_once(dirname(__FILE__)."libjpgraph-3.5.0b1srcjpgraph_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类初始化后定义格式

$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');

此处找到解决方案

我有同样的问题,这是我的解决方案:只需添加"ClearTheme()",像这样:

     $graph = new Graph(310,200); 
     $graph->ClearTheme();    

这是由于Add()使用主题默认设置。有两种解决方案

  1. 在应用设置前添加绘图
  2. $graph->SetScale()之后删除主题$graph->graph_theme = null;或调整主题

来源:/docs/chunkhtml/ch29.html -第七部分。主题类

我最近挖掘到这一点,因为我的图例也没有正确显示JpGraph:如何控制x/y偏移,边距和颜色在v3.5.0b1时使用AccBarPlot?

最新更新