ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Getting Color from Line
Posted by Aidan on Oct-13-2020 20:13
Sure this must be simple, but I can't get it to work!

I want to text boxes on to a multi-line chart, and give them the same font color as the line they relate to.  ie, this but with a dynamic color instead of red:

  $dataSetObj = $layer->addDataSet($ydata, -1, "$line1[1]");
  $layer->setXData($xdata);
  $textbox = $c->addText($x_max,$y_max,"$line1[1]");
  $textbox->setFontcolor(0xFF0000);

I've tried this and several variations, but I think I'm missing something basic!:

  $textbox->setFontcolor($layer->Getcolor());

  Re: Getting Color from Line
Posted by Peter Kwan on Oct-14-2020 10:47
Hi Aidan,

To ensure things are of the same color, the best method is to specify the color for both the line and the text, as opposed to letting ChartDirector automatically assign the color. It is like:

https://www.advsofteng.com/doc/cdphp.htm#multiline2.htm

If the color is set to -1 for the line, when the line is actually drawn, ChartDirector will assign a color from the data color list in the color palette. See:

https://www.advsofteng.com/doc/cdphp.htm#colorspec.htm

The colors will then be denoted as DataColor + 0, DataColor + 1, DataColor + 2, ....

In this case, to get the color, you have to know which index the line is. For example, if the line is the first line in the chart, it is :

#Assume this is the first line
$dataSetObj = $layer->addDataSet($ydata, -1, "$line1[1]");

#The text color is then:
$textbox->setFontcolor(DataColor + 0);

Hope this can help.

Regards
Peter Kwan

  Re: Getting Color from Line
Posted by Aidan on Oct-15-2020 18:23
Brilliant, thanks Peter, that's just what I needed!