douqianke7467 2013-12-17 18:39
浏览 64
已采纳

JPGraph - 条形图未显示值

I'm using the latest version of JPGraph and I'm trying to alter the graph_api file to show values on Group Bar Plots. Here's a snippet of code to show my alterations (for those looking at the API, this is in the graph_group function):

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

According to the API, using "value->show()" should display the values. When I add in that last line (for $gbplot), the graph doesn't show. If I comment it out, the graph will display sans values. What am I missing?

  • 写回答

1条回答 默认 最新

  • doulian8742 2013-12-18 18:40
    关注

    Apparently the issue has to deal with the fact that JPGraph won't let you overwrite its theme by default. I found by setting the theme to null allowed me to make more extensive changes. IMO, that's a pretty dumb setup, but c'est la vie. Here's what my graph definition looks like now:

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

    The 'graph_theme' line is the new addition made that fixed the issue for me. I hope this helps others in the future as it's not explicitly stated in their API.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码