7

jpgraph と XAMPP を使い始めたばかりで、バープロットを作成しようとしていました。Web でいくつかの記事を読んでいたところ、色の配列を setfillcolor に渡して、各バーが異なる色になるようにできると書かれていました。ただし、色を渡すたびに、グラフはデフォルトの水色から変化しません。

グラフはデータの変化には反応しますが、色の変化には反応しません。累積棒グラフの例で試してみましたが、色に反応しているようです。

このような問題を診断する方法がわかりません。助けてください!

以下のコード (オレンジ色から #B0C4DE に色が変更された Jpgraph ドキュメントの例 [元の例のオレンジ色は表示されません]):

<?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();
?>
4

3 に答える 3

19

私は同じ問題を抱えていました。私が見つけた解決策は、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');

ここにある解決策

于 2011-08-09T06:27:49.950 に答える
11

私は同じ問題を抱えており、これが私の解決策です。次のように「ClearTheme()」を追加するだけです:

     $graph = new Graph(310,200); 
     $graph->ClearTheme();    
于 2016-03-11T13:33:07.133 に答える
5

これはAdd()、テーマのデフォルト設定を使用しているためです。2つの解決策があります

  1. 設定を適用する前にプロットを追加
  2. $graph->graph_theme = null;後でテーマを削除$graph->SetScale()するか、テーマを調整します

ソース: /docs/chunkhtml/ch29.html - パート VII。テーマクラス

私の凡例も正しく表示されていなかったので、最近これを掘り下げましたJpGraph: How to control x/y offset, margins and color in v3.5.0b1 when using AccBarPlot?

于 2012-05-11T17:43:51.733 に答える