On Bar series how to show Y value as Mark and Label

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
occ
Newbie
Newbie
Posts: 5
Joined: Wed Jul 20, 2005 4:00 am

On Bar series how to show Y value as Mark and Label

Post by occ » Wed Nov 28, 2012 4:04 pm

I'm new to TeeChart but am currently on an older version (v2) and am having difficult getting to grips with things so please excuse me.
I'm running in VS2010 targeting .NET 2.0.

My data consists of an Organisation Name and an Amount (summed).
I'm trying to programmatically show a Bar series where the Y value of the bar is the amount, the text under each bar (bottom axis) is the Organisation Name and at the top of each bar display the actual Y value.

I built a quick little app so I could play around rather than having to start my full app so I've got this:

Code: Select all

ClearChart();
using (var ds = GetPaymentsData())
{
	var barSeries = new Bar();
	tc.Series.Add(barSeries);
	//barSeries.LabelMember = "OrganisationName";
	barSeries.ColorEach = true;
	barSeries.Marks.Visible = true;
	barSeries.YValues.DataMember = "Amount";
	barSeries.DataSource = ds;
}
ds is a single table DataSet. As you can see by the commented out line I tried a few things.
As it is above it displays the YValue at the top of each bar but the text on the bottom axis under each bar appears to be just some ordinal value starting at 0.

If I uncomment the LabelMember line above then I get the Organisation Name under each bar on the bottom axis but then it also shows it as the value above each bar.

Attempting to set the barSeries.XValues.DataMember just gives format exception because organisation name is a string.

This must surely be possible I just can't see how to do it. I've tried looking at both the series and axis tutorials in the HTML help docs but they don't shed much light. I tried loading the demo project but it crashes in VS2010 when you click on demo from the tree view when it attempts to Activator.CreateInstance(t).

Any help much appreciated.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: On Bar series how to show Y value as Mark and Label

Post by Sandra » Thu Nov 29, 2012 12:33 pm

Hello occ,

I am very grateful if you can send us a simple example we can run "as-is" here, because we can reproduce your problem and try to find a solution for your use?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

occ
Newbie
Newbie
Posts: 5
Joined: Wed Jul 20, 2005 4:00 am

Re: On Bar series how to show Y value as Mark and Label

Post by occ » Thu Nov 29, 2012 3:53 pm

Hi,

Okay is a simply example VS2010 app that uses TeeChart v2 and targets .NET 2.0.
I've also attached a screenshot of the this test app with indicators of what I am trying to achieve.

Regards,
Peter
Attachments
exampleTChartAppScreenshot.png
Screenshot with text on to indicator what I want.
exampleTChartAppScreenshot.png (54.04 KiB) Viewed 11815 times
BarChartTest.7z
VS2010 test app
(10.03 KiB) Downloaded 506 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: On Bar series how to show Y value as Mark and Label

Post by Sandra » Fri Nov 30, 2012 12:10 pm

Hello occ,

Ok. I have modified your code, where I have used GetSeriesMark event to change the text of Marks

public Form1()

Code: Select all

		{
			InitializeComponent();

			var barSeries = new Bar(tChart1.Chart);
            barSeries.ColorEach = true;
			barSeries.Marks.Visible = true;
            barSeries.Marks.Style = MarksStyles.Label;
            barSeries.LabelMember = "OrganisationName";
            barSeries.YValues.DataMember = "Amount";
			barSeries.DataSource = MakeData();
            barSeries.GetSeriesMark  = new Series.GetSeriesMarkEventHandler(barSeries_GetSeriesMark);

		}

        void barSeries_GetSeriesMark(Series series, GetSeriesMarkEventArgs e)
        {
            if (e.ValueIndex != -1)
            {
                if (e.ValueIndex == 0)
                {
                    e.MarkText = series.YValues[e.ValueIndex].ToString();
                }
           
            }
        }
  
        private DataSet MakeData()
		{
			var ds = new DataSet();
			var dt = new DataTable();
			dt.Columns.Add("OrganisationName", typeof(string));
			dt.Columns.Add("Amount", typeof(decimal));
			ds.Tables.Add(dt);

			dt.Rows.Add("Microsoft", 1234.00);
			dt.Rows.Add("Apple", 234.00);
			dt.Rows.Add("Google", 345.00);

			return ds;
		}
Could you please tell us if previous code works in your end ?

I hope will helps.


Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: On Bar series how to show Y value as Mark and Label

Post by Sandra » Fri Nov 30, 2012 12:11 pm

Hello occ,

Ok. I have modified your code, where I have used GetSeriesMark event to change the text of Marks:

Code: Select all

public Form1()
		{
			InitializeComponent();

			var barSeries = new Bar(tChart1.Chart);
            barSeries.ColorEach = true;
			barSeries.Marks.Visible = true;
            barSeries.Marks.Style = MarksStyles.Label;
            barSeries.LabelMember = "OrganisationName";
            barSeries.YValues.DataMember = "Amount";
			barSeries.DataSource = MakeData();
            barSeries.GetSeriesMark  = new Series.GetSeriesMarkEventHandler(barSeries_GetSeriesMark);

		}

        void barSeries_GetSeriesMark(Series series, GetSeriesMarkEventArgs e)
        {
            if (e.ValueIndex != -1)
            {
                if (e.ValueIndex == 0)
                {
                    e.MarkText = series.YValues[e.ValueIndex].ToString();
                }
           
            }
        }
  
        private DataSet MakeData()
		{
			var ds = new DataSet();
			var dt = new DataTable();
			dt.Columns.Add("OrganisationName", typeof(string));
			dt.Columns.Add("Amount", typeof(decimal));
			ds.Tables.Add(dt);

			dt.Rows.Add("Microsoft", 1234.00);
			dt.Rows.Add("Apple", 234.00);
			dt.Rows.Add("Google", 345.00);

			return ds;
		}
Could you please tell us if previous code works in your end ?

I hope will helps.


Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

occ
Newbie
Newbie
Posts: 5
Joined: Wed Jul 20, 2005 4:00 am

Re: On Bar series how to show Y value as Mark and Label

Post by occ » Fri Nov 30, 2012 2:11 pm

Hi,

Thanks for that :D . A bit of crossed wires between my first post description and the example as I want all the bars to have the value shown as the label.
So in fact the required code is as simple as adding:

Code: Select all

barSeries.Marks.Style = MarksStyles.Value;
Anyhow your posted code was great as I might need to add some formatting and hence add a handler to set the text as you had in your example.

Thanks again,
Peter

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: On Bar series how to show Y value as Mark and Label

Post by Sandra » Mon Dec 03, 2012 10:31 am

Hello Peter,

I am glad my solution helps you :D. If you have any problems please, let me know.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: On Bar series how to show Y value as Mark and Label

Post by Sandra » Mon Dec 03, 2012 10:31 am

Hello Peter,

I am glad my solution helps you :D. If you have any problems please, let me know.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply