【问题标题】:Teechart PHP CalcXPosreturning 0Techart PHP CalcXPos 返回 0
【发布时间】:2018-10-02 05:09:08
【问题描述】:

我一直在尝试使用 Techart 为一个项目绘制几个图表。我已经成功地绘制了图表。我正在努力用一些标签来注释图表上的特定点。

具体问题是当我使用 $chart1->CalcXPos(someIndex);它总是返回 0 而不是像素值。我该如何解决这个问题?

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

【问题讨论】:

  • 能否添加一些示例代码?
  • 已添加示例代码。我很抱歉。

标签: php annotations teechart


【解决方案1】:

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

$chart1->doInvalidate();

【讨论】:

  • 你是冠军
  • 还有耶,既然我已经引起了你的注意,你是否也知道如何更改轴的格式以显示小数?我一直在尝试以下方法:$chart1->getAxes()->getLeft()->getLabels()->setValueFormat('#,##0.###'); 不幸的是,上述方法不起作用,我仍然得到一堆 1 1 1 0 0 0 -1 -1 -1(从上到下)
  • Steema Software 提供多个support options
  • 我已添加票证#2107。作为一种解决方法,您可以尝试使用OnGetAxisLabel 事件,如“Axes\OnGetAxisLabel 事件”示例here 中所示。但是,请针对不同的问题提出新问题。
  • 再次感谢 Yeray。你太棒了!我会记住针对不同问题的新问题!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-17
  • 2012-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多