Jump to content
Software FX Community

Series label within the chart body


Asif_Khan
 Share

Recommended Posts

I have a line chart with upto 15 (or even more) series. the problem that i am facing is the duplication of colors. it becomes very difficult to distinguish between the plotted lines and relate them to a specific item in the legend box. An easy solution which i can think of is to put a single label on each line which would represent which item in the legend box actually relate to the line.

Can this be done? if yes then please let me know how to get this sorted.

Many thanks in advance!

Link to comment
Share on other sites

 You can label the last point of each series, and align the label to the right of the last marker:

private void LabelSeries (int seriesIndex)

{

  PointAttributes lastPoint = chart1.Points[seriesIndex,chart1.Data.Points - 1];

  lastPoint.PointLabels.Visible =

true;  lastPoint.PointLabels.Alignment = StringAlignment.Near;  lastPoint.PointLabels.Format = "%L";

  lastPoint.Text = chart1.Series[seriesIndex].Text;

}

 

for (int i = 0; i < chart1.Data.Series; i++)

  LabelSeries(i);

 

Nothing will guarantee that the labels are not going to overlap with each other.

Link to comment
Share on other sites

Frank, many thanks for your reply.

I need some further assistance. using the provided code, the labels can now be produced at the last point on the chart. However, this is not very useful as it is not necessary that all series on the graph would have data available and hence as a result some of the series do not have the label. secondly, it would be good to have this label on the first point on each series.

Is there any way this could be acheived?

Thanks for being helpful.

Link to comment
Share on other sites

> it is not necessary that all series on the graph would have data available ...

If a series has no data at all, what's the label for? You asked how to put the label besides the line. If there is no data there is no line.

> it would be good to have this label on the first point on each series

This can be easily derived from my code:

PointAttributes firstPoint = chart1.Points[seriesIndex,0];

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...