【问题标题】:JPGraph - Bar Graphs are not showing valuesJPGraph - 条形图不显示值
【发布时间】:2014-01-05 16:27:25
【问题描述】:

我正在使用最新版本的 JPGraph,并且我正在尝试更改 graph_api 文件以在组条形图上显示值。这是一段代码,用于显示我的更改(对于那些查看 API 的人,这是在 graph_group 函数中):

$tot = new BarPlot( array_values( $total ) );
$tot->value->show();
$tot->value->SetFormat('%2d');
$tot->value->SetColor('black','black');
$tot->value->SetFont($t_graph_font,FS_BOLD,9);
$tot->SetFillColor('lightblue');
$tot->SetWidth(0.7);
$tot->SetLegend( lang_get( 'legend_total' ) );
$graph->Add($tot);

$p1 = new BarPlot( array_values( $p_metrics['open'] ) );
$p1->SetFillColor( 'yellow' );
$p1->SetWidth( 1 );
$p1->SetLegend( plugin_lang_get( 'legend_opened' ) );
$p1->value->show();
$p1->value->SetColor('white','white');
$p1->value->SetFormat('%2d');
$p1->value->SetFont($t_graph_font,FS_BOLD,8);
$p1->SetFillColor('red');
$p1->SetLegend( lang_get( 'legend_still_open' ) );

$p2 = new BarPlot( array_values( $p_metrics['closed'] ) );
$p2->SetFillColor( 'blue' );
$p2->SetWidth( 1 );
$p2->SetLegend( plugin_lang_get( 'legend_closed' ) );
$p2->value->show();
$p2->value->SetFormat('%2d');
$p2->value->SetColor('black','black');
$p2->SetFillColor('forestgreen');
$p2->SetWidth(0.5);
$p2->SetLegend( lang_get( 'legend_closed' ) );

$gbplot = new GroupBarPlot( array( $p1, $p2 ) );
$gbplot->value->show();

$graph->Add( $gbplot );

根据 API,使用“value->show()”应该显示值。当我添加最后一行(对于 $gbplot)时,图表没有显示。如果我将其注释掉,图表将显示无值。我错过了什么?

【问题讨论】:

  • 您不需要使用$graph->Add()将条形图(或GroupBarPlot)添加到您的图表吗?
  • 抱歉,我没有发那么远。我将它添加到图表中。我正在更新 sn-p 以解决这个问题。

标签: php jpgraph


【解决方案1】:

显然,问题必须处理 JPGraph 默认情况下不允许您覆盖其主题的事实。我发现通过将主题设置为 null 可以让我进行更广泛的更改。 IMO,这是一个非常愚蠢的设置,但是 c'est la vie。这是我的图形定义现在的样子:

$graph = new Graph( $p_graph_width, $p_graph_height );
$graph->SetScale('textlin');
$graph->graph_theme = null;
$graph->SetFrame(false);

“graph_theme”行是为我解决问题的新增内容。我希望这对未来的其他人有所帮助,因为他们的 API 中没有明确说明。

【讨论】:

    【解决方案2】:

    原因在这里: // 更改每个绘图设计的方法应在 after $graph->add($plot) 方法后使用。 // 这真的违反直觉。但它有效!

    $graph->Add($bplot);
    $bplot->value->show();
    

    // 感谢:http://webdeveloperoddities.blogspot.com/2010/10/jpgraph-cannot-change-line-colour-or.html

    【讨论】:

      猜你喜欢
      • 2013-08-29
      • 2012-06-18
      • 2011-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-07
      相关资源
      最近更新 更多