Forum > TAChart

Adding Text into a Chart

(1/2) > >>

Might be simple, but haven't really found what I'm trying to do in the examples and poking around here.

Looking to be able to add a simple text into an existing chart. This is not quite the same as a hint which uses the data of that series to draw the hint.

For example say I have a chart with some areas that I would like to identify with some basic text, and place where I would like. This text still need it to scale (or position) with the chart as the user may pan or zoom.

I can calculate an xy value based on the series to come up with points myself to place. 

I was almost thinking of something like a line series with the line not drawn but the points and hints always drawn if that makes sense as a hack, but not sure.

Attached is a sample of what I'm trying to do.



This is everything else than simple.
There are a lot of ways to do this.

I would suggest to add a new series and to scale it alike the existing series. Where the text shall appear, you write something as "..AddXY(value,...'mytext');
And format the marks as you like.

This is 1 non debugged way of 100 ways to do it.

If you do not like it, please tell us:
What type of series do you use?
With which code line do you add your data?

Thanks, I think we are thinking of the same idea.

I'll create a new series for each of the single points with the text I need. Will use the same scale as the main graph. Might make it easier to keep track and update if needed.

Will see how far I get.

Off hand any examples of owner draw labels?  I went through a bunch of the demos but didn't see one... or just missed it  :)



Yes, that's exactly the way I would do it: add a line series with the label texts added along with the x/y values, Marks.Style = smsLabel, ShowLines=false and ShowPoints= false. And set the series' Legend.Visible to false to avoid the "text series" to appear in the legend. There is also no way to center the text to the x/y coordinate specified in the AddXY method, it will always be above or below the point, depending on MarkPositions; the closest you can get is setting Marks.Distance to 0.

While writing this I had the idea that there is alway the OnDrawEvent which fires after the chart has been drawn completely, and you have a last chance to add something to it. And this works also when you are willing to write some code - see the attached demo. One tiny difference though: While in the "text series" method the position of the extra text labels is used for calculating the axis scale, this is not done in the event method.

Thanks will take a look at the sample.

I created a simple line series, changed some options not to display the line, and as smsLabel and worked like a champ.

Actually very simple with help from folks here!!

The text is always the same, so using the AddXY() with the fixed text at a correct location will do the job.

Just need to come up with a good way to compute X and Y so labels are where they should be. That's hopefully easy the way I'm thinking.

Thanks for the awesome and quick help!



[0] Message Index

[#] Next page

Go to full version