0

I've been trying to use Teechart to draw a couple of graphs for a project. 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); it always returns 0 instead of a value of the pixels. 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");
2
  • could you please add some sample code? Commented Oct 2, 2018 at 5:17
  • Sample code has been added. My apologies.
    – Teg Singh
    Commented Oct 2, 2018 at 6:16

1 Answer 1

0

Try forcing a chart repaint before using Calc* functions:

$chart1->doInvalidate();
5
  • You are a champion <3. For future help, how can I reach out to you Yeray? I am unable to register onto Steema forums, and I am using Teechart as part of my coursework.
    – Teg Singh
    Commented Oct 2, 2018 at 11:55
  • Also Yeray, since I have your attention, would you also know how to change format of axis to display decimals? I've been trying the following: $chart1->getAxes()->getLeft()->getLabels()->setValueFormat('#,##0.###'); Unfortuantely the above isn't working and I still get a bunch of 1 1 1 0 0 0 -1 -1 -1 (top to bottom)
    – Teg Singh
    Commented Oct 2, 2018 at 11:59
  • Steema Software offers several support options.
    – Yeray
    Commented Oct 3, 2018 at 8:35
  • I've added the ticket #2107. As a workaround you could try using the OnGetAxisLabel event as shown in the "Axes\OnGetAxisLabel Event" example here. But please, open new questions for different issues.
    – Yeray
    Commented Oct 3, 2018 at 8:57
  • Thank you once again Yeray. You are amazing! I shall keep new questions for different issues in mind!
    – Teg Singh
    Commented Oct 3, 2018 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.