简体   繁体   English

Teechart PHP CalcXPos返回0

[英]Teechart PHP CalcXPosreturning 0

I've been trying to use Teechart to draw a couple of graphs for a project. 我一直在尝试使用Teechart为一个项目绘制几个图形。 I've managed to draw the graphs just fine. 我设法画好了图。 What I am struggling with is annotating specific points on the graph with some labels. 我正在努力的是在图形上用一些标签注释特定的点。

The specific problem is that when I use $chart1->CalcXPos(someIndex); 具体的问题是当我使用$ chart1-> CalcXPos(someIndex);时。 it always returns 0 instead of a value of the pixels. 它总是返回0而不是像素值。 How can I got about resolving this? 我该如何解决这个问题?

    $chart1 = new TChart(640,480);

    $varname = new Line($chart1->getChart()); 

    $someYValues = array(2,3,5,7,11,13);
    $theXValues = array(-3,-1,1,3,4,5);

    $i=0;
    foreach($someYValues as $x){
        $varname->addXY($theXValues[$i],$someYValues[$i]);
        $i++;
    }        

    $varname->Setcolor(Color::BLUE()); 
    $chart1->getAxes()->getBottom()->getTitle()->setText("X-axis label (units)"); 
    $chart1->getAxes()->getLeft()->getTitle()->setText("Y-axis label (units)"); 

    $tool=new Annotation($chart1->getChart());
    $tool->getShape()->setCustomPosition(true);

    //$chart1->paint;

    $xvalue = $chart1->getAxes()->getBottom()->CalcXPosValue($theXValues[2]);
    $yvalue = $chart1->getAxes()->getLeft()->CalcYPosValue($someYValues[2]);

    //$xvalue = $varname->CalcXPosValue($theXValues[2]);
    //$yvalue = $varname->CalcYPosValue($someYValues[2]);

    echo $xvalue;
    echo $yvalue;

    $tool->setTop($xvalue);
    $tool->setLeft($yvalue);

    $tool->setText("Random Text ");

    $chart1->render("ecg.png");

在使用Calc*函数之前,尝试强制图表重绘:

$chart1->doInvalidate();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM