C1 Community
ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Is it possible to have a ChartDataSeries Label with an Image?

rated by 0 users
This post has 9 Replies | 1 Follower

Top 500 Contributor
Posts 23
LMunnis Posted: Wed, Apr 15 2009 6:47 PM

I am setting my C1Chart ChartDataSeries.Label to a string value, but I would like to have it be a combination of string and an image.  Is this possible?

Top 25 Contributor
Posts 372

 Hello,

Yes, this is possible.  When creating/editing a label, specify the text you would like the label to display and specify the image location.  Ensure that the label is large enough to display both the string and the image.

Regards,

Raleigh

Top 500 Contributor
Posts 23
LMunnis replied on Fri, Apr 17 2009 11:19 AM

Thanks for the reply, but I don't quite understand what you mean by "specify the image location".  Here is how I'm doing it:

ChartDataSeries cds = _c1Chart.ChartGroups[0].ChartData.SeriesList.AddNewSeries();

cds.Label = taskName;  

 How do I specify the image location?  cds.Label is just a string, it's not a C1 object.  I am using C1.Win.C1Chart.2 runtime version 2.0.50727.

 Thanks!

 

Top 25 Contributor
Posts 372

Hello,

It is easiest to add an image to a chart label by using the Label Editor.  For more information on this, please refer to our documentation.  The following code snippet is an example of how to do this using code.

            C1.Win.C1Chart.Label lab = c1Chart2.ChartLabels.LabelsCollection[0];
            lab.AttachMethod = AttachMethodEnum.DataCoordinate;
            lab.AttachMethodData.X = 2004;
            lab.AttachMethodData.Y = 50;
            PictureBox pic = new PictureBox();
            pic.Image = Line_Chart.Properties.Resources.TipBackground;
            lab.Size = new Size(100, 100);
            lab.Image = pic.Image;
            lab.Visible = true;

I hope this helps.

   -Raleigh
Top 25 Contributor
Posts 372

Hello again,

Alternatively, you could do this without using a picturebox by doing the following:

            C1.Win.C1Chart.Label lab = c1Chart2.ChartLabels.LabelsCollection[0];
            lab.AttachMethod = AttachMethodEnum.DataCoordinate;
            lab.AttachMethodData.X = 2004;
            lab.AttachMethodData.Y = 50;
            lab.Size = new Size(100, 100);  // adjust label size to accomodate image
            lab.Image = Line_Chart.Properties.Resources.TipBackground;

 I have attached a sample that does this in code and in the label editor.

-Raleigh

Top 500 Contributor
Posts 23
LMunnis replied on Sun, Apr 19 2009 10:02 AM

Raleigh, thanks for the code example and project, I will check it out!

Top 500 Contributor
Posts 23
LMunnis replied on Wed, Apr 22 2009 10:51 AM

I'm having problems looking at this, since I am still using Visual Studio 8, it's not recognizing the solution.  Can you post a screenshot of the executing program so I can see what the labels look like?

Top 25 Contributor
Posts 372

 Hello,

I have posted a screenshot and a sample app for you in Visual Studio 2005 (vs8). Please note that there have been a few changes in the code and the correct code is listed below.

            C1.Win.C1Chart.Label lab = new C1.Win.C1Chart.Label();
            lab = c1Chart2.ChartLabels.LabelsCollection.AddNewLabel();
            lab.Visible = true;
            lab.Text = "Test";
            lab.Size = new Size(100, 100);
            lab.Image = WindowsApplication2.Properties.Resources.TipBackground;
            lab.AttachMethod = AttachMethodEnum.DataCoordinate;
            lab.AttachMethodData.GroupIndex = 0;
            lab.AttachMethodData.X = 2005;
            lab.AttachMethodData.Y = 100;

The code that I provided before assumed that a label already existed on the chart.  Sorry if this mix-up caused you any problems. Best of luck.

- Raleigh

Top 500 Contributor
Posts 23
LMunnis replied on Wed, May 6 2009 10:15 AM

Hi again,

 This isn't exactly what I'm after - in the picture you have attached, imagine if I wanted an icon for each year on the y-axis, i.e.some little icon beside the "60" and a different one beside the "80".  I'd show you an image but I can't figure out how to attach something to one of these messages. Thanks!

Top 25 Contributor
Posts 372

 Hello,

 First to attach a file in our forums, click the "Options" tab and then click the "Add/Update" button to load the file.  Now, to get labels with an image on the Y-Axis try this:

            c1Chart2.ChartArea.AxisY.Text = "";   // helps visibility but not needed

            c1Chart2.ChartArea.AxisY.AnnoMethod = AnnotationMethodEnum.ValueLabels;   // clears Y-axis if no value labels exist
            C1.Win.C1Chart.Label lab_y = new C1.Win.C1Chart.Label();
            lab_y = c1Chart2.ChartLabels.LabelsCollection.AddNewLabel();
            lab_y.Visible = true;
            lab_y.Text = "Y Test";
            lab_y.Style.ForeColor = Color.Red;
            lab_y.Size = new Size(50, 50);
            lab_y.Image = WindowsApplication2.Properties.Resources.TipBackground;
            lab_y.AttachMethod = AttachMethodEnum.DataIndexY;
            lab_y.AttachMethodData.GroupIndex = 0;
            lab_y.AttachMethodData.Y = 100;
            lab_y.AttachMethodData.X = 0;
            lab_y.AttachMethodData.SeriesIndex = 0;
            lab_y.AttachMethodData.PointIndex = 0;
            lab_y.Offset = -1;

This may require a little modification on your part, but I think this is what your looking for.  I hope this helps.

-Raleigh

Page 1 of 1 (10 items) | RSS
Contact ComponentOne: 1.800.858.2739 ©1987-2010 ComponentOne LLC All Rights Reserved.