【问题标题】:Overlay Text on bar in JpGraph在 JpGraph 中的条上叠加文本
【发布时间】:2012-07-15 17:46:54
【问题描述】:

我正在使用 JpGraph 制作一个甘特图来进行会议。我在页面底部找到了this 示例,我正在尝试将其更改为我需要显示的内容。我能够将leftMark 设置到我希望文本出现的栏的一侧。但是,文本不在栏内。我试图将对齐更改为"left, top",但我收到错误$bar->leftMark->title->SetTextAlign('left','top');

致命错误:调用未定义的方法 Text::SetTextAlign() in C:\xampp\htdocs\ganttChart\chart.php 在第 82 行

或对图表没有影响。

请看我的例子,我可以用图表做什么:example

问题:

  1. 为了完成此任务,我缺少哪些类、包含或代码?

  2. 您是否知道我可以遵循的示例与我正在寻找的效果相同,如上面的段落和示例中所述?

PHP 代码:

<?php // content="text/plain; charset=utf-8"
// Gantt hour example
require_once ('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_gantt.php');
require_once ('jpgraph/src/jpgraph_canvas.php');
require_once ('jpgraph/src/jpgraph_canvtools.php');
require_once ('jpgraph/src/jpgraph_text.inc.php');


// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
$graph = new GanttGraph();
$graph->SetMarginColor('blue:1.7');
$graph->SetColor('white');

$graph->SetBackgroundGradient('navy','white',GRAD_HOR,BGRAD_MARGIN);
$graph->scale->hour->SetBackgroundColor('lightyellow:1.5');
$graph->scale->hour->SetFont(FF_FONT1);
$graph->scale->day->SetBackgroundColor('lightyellow:1.5');
$graph->scale->day->SetFont(FF_FONT1,FS_BOLD);

$graph->title->Set("Example of hours in scale");
$graph->title->SetColor('white');
$graph->title->SetFont(FF_VERDANA,FS_BOLD,14);

$graph->ShowHeaders(GANTT_HDAY | GANTT_HHOUR);

$graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY);
$graph->scale->week->SetFont(FF_FONT1);
$graph->scale->hour->SetIntervall(1);

$graph->scale->hour->SetStyle(HOURSTYLE_HM24);
$graph->scale->day->SetStyle(DAYSTYLE_SHORTDAYDATE3);

$data = array(
    array(0,"Room 1", "2001-01-26 04:30","2001-01-26 14:00"),
    array(0,"Room 1", "2001-01-26 15:30","2001-01-26 19:00"),
    array(1,"Room 2", "2001-01-26 10:00","2001-01-26 18:00"),
    array(2,"Room 3", "2001-01-26","2001-01-27 10:00")
);


for($i=0; $i<count($data); ++$i) {

    $bar = new GanttBar(
    $data[$i][0],
    $data[$i][3],
    $data[$i][2],
    $data[$i][3],
    "",100);

    if( count($data[$i])>4 )
    $bar->title->SetFont($data[$i][4],$data[$i][5],$data[$i][6] );
    $bar->SetPattern(BAND_RDIAG,"yellow");
    $bar->SetFillColor("red");
    //$bar->SetTextAlign('left');

    $bar->leftMark->Show();    
    //$bar->rightMark->title->Set("Events name");
    $bar->leftMark->title->Set("Events name");
    //$bar->rightMark->SetType(MARK_FILLEDCIRCLE);
    //$bar->rightMark->SetWidth(10);
    //$bar->rightMark->SetColor("red");
    //$bar->rightMark->SetFillColor("red");
    //$bar->leftMark->title->SetTextAlign('left');
    $bar->leftMark->title->Center(50,150,75);
    $bar->leftMark->title->SetFont(FF_ARIAL,FS_BOLD,12);
    $bar->leftMark->title->SetColor("black");
    $bar->leftMark->title->SetAlign('left','top');
    $graph->Add($bar);
}


$graph->Stroke();



?>

【问题讨论】:

    标签: php text-alignment jpgraph


    【解决方案1】:

    我想通了,请参阅下面的示例和代码:Example

    代码:

    <?php // content="text/plain; charset=utf-8"
    // Gantt hour example
    require_once ('jpgraph/src/jpgraph.php');
    require_once ('jpgraph/src/jpgraph_gantt.php');
    require_once ('jpgraph/src/jpgraph_canvas.php');
    require_once ('jpgraph/src/jpgraph_canvtools.php');
    require_once ('jpgraph/src/jpgraph_text.inc.php');
    
    
    // Report simple running errors
    error_reporting(E_ERROR | E_WARNING | E_PARSE);
    
    // Reporting E_NOTICE can be good too (to report uninitialized
    // variables or catch variable name misspellings ...)
    error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
    
    // Report all errors except E_NOTICE
    // This is the default value set in php.ini
    error_reporting(E_ALL ^ E_NOTICE);
    
    // Report all PHP errors (see changelog)
    error_reporting(E_ALL);
    
    // Report all PHP errors
    error_reporting(-1);
    
    
    
    // Same as error_reporting(E_ALL);
    ini_set('error_reporting', E_ALL);
    $graph = new GanttGraph();
    $graph->SetMarginColor('blue:1.7');
    $graph->SetColor('white');
    
    $graph->SetBackgroundGradient('navy','white',GRAD_HOR,BGRAD_MARGIN);
    $graph->scale->hour->SetBackgroundColor('lightyellow:1.5');
    $graph->scale->hour->SetFont(FF_FONT1);
    $graph->scale->day->SetBackgroundColor('lightgreen:1.5');
    $graph->scale->day->SetFont(FF_FONT1,FS_BOLD);
    
    $graph->title->Set("Example of hours in scale");
    $graph->title->SetColor('white');
    $graph->title->SetFont(FF_VERDANA,FS_BOLD,14);
    
    $graph->ShowHeaders(GANTT_HDAY | GANTT_HHOUR);
    
    $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY);
    $graph->scale->week->SetFont(FF_FONT1);
    $graph->scale->hour->SetIntervall(1);
    
    $graph->scale->hour->SetStyle(HOURSTYLE_HMAMPM);
    $graph->scale->hour->grid->SetColor('lightgray');
    $graph->scale->day->SetStyle(DAYSTYLE_SHORTDAYDATE3);
    
    
    $data = array(
        array(0,"Room 1", "2001-01-26 02:30","2001-01-26 14:00:00","Sonic"),
        array(0,"Room 1", "2001-01-26 15:30","2001-01-26 19:00","SailorMoon"),
        array(1,"Room 2", "2001-01-26 10:00","2001-01-26 18:00","Gundam Wing"),
        array(2,"Room 3", "2001-01-26","2001-01-26 10:00","No appologies")
    );
    
    
    for($i=0; $i<count($data); ++$i) {
    
    $txt = new Text();
    $txt->SetScalePos($data[$i][2],$data[$i][0]);
    $txt->SetMargin(50);
    $txt->SetFont(FF_VERDANA,FS_BOLD,12);
    $txt->SetAlign('left','center');
    $txt->Set($data[$i][4]);
    $txt->SetParagraphAlign('left');
    //$txt->SetWordWrap(10);
    $txt->SetBox('lightyellow');
    $txt->SetShadow();
    $graph->Add($txt); 
    
    
        $bar = new GanttBar(
        $data[$i][0],
        $data[$i][1],
        $data[$i][2],
        $data[$i][3],
        $data[$i][4],100);
    
        if( count($data[$i])>4 )
        $bar->title->SetFont($data[$i][4],$data[$i][5],$data[$i][6] );
        $bar->title->SetFont(FF_VERDANA,FS_BOLD,12);
        $bar->SetPattern(BAND_RDIAG,"yellow");
        $bar->SetFillColor("red");
        $graph->Add($bar);
    }
    
    $graph->Stroke();
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-24
      • 2016-07-13
      • 2020-03-28
      • 1970-01-01
      • 1970-01-01
      • 2021-03-21
      • 2012-11-30
      相关资源
      最近更新 更多