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.

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

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题