Page 1 of 1

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

Posted: Wed Nov 28, 2012 4:04 pm
by 9637806
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.

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

Posted: Thu Nov 29, 2012 12:33 pm
by 10050769
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,

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

Posted: Thu Nov 29, 2012 3:53 pm
by 9637806
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

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

Posted: Fri Nov 30, 2012 12:10 pm
by 10050769
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,

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

Posted: Fri Nov 30, 2012 12:11 pm
by 10050769
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,

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

Posted: Fri Nov 30, 2012 2:11 pm
by 9637806
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

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

Posted: Mon Dec 03, 2012 10:31 am
by 10050769
Hello Peter,

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

Thanks,

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

Posted: Mon Dec 03, 2012 10:31 am
by 10050769
Hello Peter,

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

Thanks,