Start position for bar series

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Chandran
Newbie
Newbie
Posts: 15
Joined: Thu Feb 07, 2013 12:00 am

Start position for bar series

Post by Chandran » Wed Feb 05, 2014 2:00 pm

Hi,

Is there any way to set start position for bar series with stack style set as self-stacked?
For instance, for the stacked bar series in attached snap, can we have starting position as 4.5 so that bar will start from this point?

We are using tee chart for .net (Version 4.1.2013.7302).

Thanks in advance,
Chandran
Attachments
BarSeries.png
Sample bar series
BarSeries.png (81.07 KiB) Viewed 15017 times

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Start position for bar series

Post by Christopher » Thu Feb 06, 2014 3:20 pm

Hello Chandran,
Chandran wrote: For instance, for the stacked bar series in attached snap, can we have starting position as 4.5 so that bar will start from this point?
One technique would be to use series labels, e.g.

Code: Select all

    Bar series1, series2;
    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      series1 = new Bar(tChart1.Chart);
      series1.Add(1, "10");
      series1.Add(2, "20");
      series1.MultiBar = MultiBars.SelfStack;

      series2 = new Bar(tChart1.Chart);
      series2.Add(3, "");
      series2.Add(4, "");
      series2.MultiBar = MultiBars.SelfStack;
    }
another technique would be to use custom labels, e.g.

Code: Select all

    Bar series1, series2;
    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      series1 = new Bar(tChart1.Chart);
      series1.Add(1, 1);
      series1.Add(2, 2);
      series1.MultiBar = MultiBars.SelfStack;

      series2 = new Bar(tChart1.Chart);
      series2.Add(3, 3);
      series2.Add(4, 4);
      series2.MultiBar = MultiBars.SelfStack;

      tChart1.Axes.Bottom.Labels.Items.Add(-1, "-10");
      tChart1.Axes.Bottom.Labels.Items.Add(0, "0");
      tChart1.Axes.Bottom.Labels.Items.Add(1, "10");
      tChart1.Axes.Bottom.Labels.Items.Add(2, "200");
    }
yet another technique would be to use the GetAxisLabel event, e.g.

Code: Select all

    Bar series1, series2;
    private void InitializeChart()
    {
      tChart1.GetAxisLabel += tChart1_GetAxisLabel;
      tChart1.Aspect.View3D = false;
      series1 = new Bar(tChart1.Chart);
      series1.Add(1, 1);
      series1.Add(2, 2);
      series1.MultiBar = MultiBars.SelfStack;

      series2 = new Bar(tChart1.Chart);
      series2.Add(3, 3);
      series2.Add(4, 4);
      series2.MultiBar = MultiBars.SelfStack;
    }

    void tChart1_GetAxisLabel(object sender, GetAxisLabelEventArgs e)
    {
      if (sender.Equals(tChart1.Axes.Bottom))
      {
        double label = Convert.ToDouble(e.LabelText);

        label += 4;

        e.LabelText = label.ToString();

        if (e.LabelText == "4")
        {
          e.LabelText = "50";
        }
      }
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Chandran
Newbie
Newbie
Posts: 15
Joined: Thu Feb 07, 2013 12:00 am

Re: Start position for bar series

Post by Chandran » Fri Feb 07, 2014 2:10 pm

Hi Christopher,

Thanks for your response.
I’ve tried the solution provided. But it is not as per our requirement.
I’ve attached an image which depicts what is expected to be rendered against the default rendering.

To elaborate more on this scenario, as shown in the “Default Rendering” image the Y-Axis starts from ‘0’.
But in our case, it should start at ‘3.8’ as shown in the “Expected Rendering” image.

Could you please suggest any solution?

Thanks,
Chandran
Attachments
StackedBarIssue.png
Sample image is attached
StackedBarIssue.png (124.36 KiB) Viewed 14939 times

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Start position for bar series

Post by Christopher » Fri Feb 07, 2014 2:18 pm

Chandran wrote:Could you please suggest any solution?
I'm afraid I'm going to need to ask you for a small code-snippet with which I can reproduce your problem, along with a little more detail of precisely what you'd like to see.

Many thanks in advance for your kind collaboration.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Chandran
Newbie
Newbie
Posts: 15
Joined: Thu Feb 07, 2013 12:00 am

Re: Start position for bar series

Post by Chandran » Tue Feb 11, 2014 1:47 pm

Hi Christopher,

Here is sample forms application illustrating what we want.
It has one bar series with 10 points. Multibars property for bar series is set to self-stacked.
As can be seen after running it, bar series is drawn from (0,0) irrespective of specified x value in series data.

Here are the issues revisited:
Issue 1: Can we draw it from any given left axis value? For instance, if we want to draw it from y=5 onwards, is it possible?
Issue 2: Since all data points in this series are having x as 4, why this bar is drawn on x=0 and why not on x = 4?
To summarize, can we have customized starting position for bar drawing, say in this case, can we make the bar drawing start from (4,20) instead (0,0)?

Please let us know in case of any more inputs/clarification.

Thanks,
Chandran
Attachments
WindowsFormsApplication2.zip
bar series sample
(16.43 KiB) Downloaded 651 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Start position for bar series

Post by Narcís » Thu Feb 13, 2014 2:46 pm

Hi Chandran,
Issue 2: Since all data points in this series are having x as 4, why this bar is drawn on x=0 and why not on x = 4?
This is because of MultiBars.SelfStack, which stacks all bars to 0.
To summarize, can we have customized starting position for bar drawing, say in this case, can we make the bar drawing start from (4,20) instead (0,0)?
Yes, a solution that solves both issues would be applying some sort of offset to the axis labels using the GetAxisLabel event, for example:

Code: Select all

using System;
using System.Drawing;
using System.Windows.Forms;
using Steema.TeeChart;
using Steema.TeeChart.Styles;

namespace WindowsFormsApplication2
{
	public partial class Form1 : Form
	{
		TChart tChart1;

		public Form1()
		{
			InitializeComponent();
			CreateChart();
			InitializeChart();
		}

        Bar series1;
        Steema.TeeChart.Drawing.PointDouble drawAt;

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            series1 = new Bar(tChart1.Chart);

            series1.BarWidthPercent = 15;
            series1.Marks.Visible = false;
            
            series1.Add(4, 10, ColorConst.First);
            series1.Add(4, 5, ColorConst.Second);
            series1.Add(4, 20, ColorConst.Third);
            series1.Add(4, 30, ColorConst.Forth);
            series1.Add(4, 5, ColorConst.Fifth);
            series1.Add(4, 40, ColorConst.Sixth);
            series1.Add(4, 25, ColorConst.Seventh);
            series1.Add(4, 10, ColorConst.Eight);
            series1.Add(4, 23, ColorConst.Nineth);
            series1.Add(4, 27, ColorConst.Tenth);

            drawAt = new Steema.TeeChart.Drawing.PointDouble(series1.XValues.Maximum, 20);

            series1.MultiBar = MultiBars.SelfStack;

            tChart1.Axes.Left.Automatic = false;
            tChart1.Axes.Left.AutomaticMaximum = false;
            tChart1.Axes.Left.AutomaticMinimum = false;

            tChart1.Axes.Left.Maximum = 200;
            tChart1.Axes.Left.Minimum = -30;

            tChart1.Axes.Bottom.Automatic = false;
            tChart1.Axes.Bottom.AutomaticMaximum = false;
            tChart1.Axes.Bottom.AutomaticMinimum = false;

            tChart1.Axes.Bottom.Maximum = 10;
            tChart1.Axes.Bottom.Minimum = 0;

            tChart1.GetAxisLabel += tChart1_GetAxisLabel;
        }

        void tChart1_GetAxisLabel(object sender, GetAxisLabelEventArgs e)
        {
          double temp = Convert.ToDouble(e.LabelText);

          if (sender.Equals(tChart1.Axes.Left))
          {
            temp += drawAt.Y;
          }
          else if (sender.Equals(tChart1.Axes.Bottom))
          {
            temp += drawAt.X;
          }

          e.LabelText = temp.ToString();
        }

		private void CreateChart()
		{               
            tChart1 = new TChart();
            tChart1.Dock = DockStyle.Fill;
            tblPanel.Controls.Add(tChart1, 0, 1);
            tblPanel.Dock = DockStyle.Fill;
		}       

        private void btnModify_Click_1(object sender, EventArgs e)
        {
            tChart1.ShowEditor();
        }
	}

    public class ColorConst
    {
        public static readonly Color First = Color.FromArgb(219, 219, 219);
        public static readonly Color Second = Color.FromArgb(222, 216, 218);
        public static readonly Color Third = Color.FromArgb(184, 186, 216);
        public static readonly Color Forth = Color.FromArgb(209, 185, 189);
        public static readonly Color Fifth = Color.FromArgb(142, 149, 189);
        public static readonly Color Sixth = Color.FromArgb(201, 147, 151);
        public static readonly Color Seventh = Color.FromArgb(90, 102, 166);
        public static readonly Color Eight = Color.FromArgb(174, 82, 98);
        public static readonly Color Nineth = Color.FromArgb(22, 45, 160);
        public static readonly Color Tenth = Color.FromArgb(155, 0, 69);
    }
}
Best Regards,
Narcís Calvet / 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

chandran
Newbie
Newbie
Posts: 6
Joined: Fri Jan 31, 2014 12:00 am

Re: Start position for bar series

Post by chandran » Thu Feb 20, 2014 1:47 pm

Thanks Narcis for the workaround. It works well provided that there is only one stacked bar series.
If chart has another series, it would also be affected with this change.

In our scenario, we do have another series and we want to apply this change to bar only.
To illustrate this, have a look at attached snaps: one is before changing axis labels, another snap shows chart after changing labels which is fine for bar but not intended for error series.

Can we just shift bar starting position to desired location and keep other series unaffected? We tried it using custom right axis for bar but haven’t succeeded in it?
Please suggest.

Thanks,
Chandran
Attachments
AfterHandlingEvent.png
After updating axis labels
AfterHandlingEvent.png (26.74 KiB) Viewed 14826 times
BeforeHandlingEvent.png
Before updating axis labels
BeforeHandlingEvent.png (26.75 KiB) Viewed 14822 times

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Start position for bar series

Post by Christopher » Fri Feb 21, 2014 10:59 am

Chandran,
chandran wrote:Can we just shift bar starting position to desired location and keep other series unaffected? We tried it using custom right axis for bar but haven’t succeeded in it?
Please suggest.
I don't think the self-stacked bar style is going to do this for you, as the XValue is always set to the index of the series in the tChart1.Series collection, that is, zero in this case. An alternative would be to use several different bar series with a stacked style, e.g.

Code: Select all

using System;
using System.Drawing;
using System.Windows.Forms;
using Steema.TeeChart;
using Steema.TeeChart.Styles;
using System.Collections.Generic;

namespace WindowsFormsApplication2
{
  public partial class Form1 : Form
  {
    TChart tChart1;

    public Form1()
    {
      InitializeComponent();
      CreateChart();
      InitializeChart();
    }

    Bar series1;
    Points series2;
    Steema.TeeChart.Drawing.PointDouble drawAt;

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      series2 = new Points(tChart1.Chart);

      series2.Add(10, 10);
      Random rnd = new Random();

      for (int i = 0; i < ColorConst.List.Count - 1; i++)
      {
        Bar series = new Bar(tChart1.Chart);
        series.BarWidthPercent = 15;
        series.Marks.Visible = false;
        series.Add(4, rnd.Next(5, 40), ColorConst.List[i]);
        series.MultiBar = MultiBars.Stacked;
      }


      //series1.Add(4, 10, ColorConst.First);
      //series1.Add(4, 5, ColorConst.Second);
      //series1.Add(4, 20, ColorConst.Third);
      //series1.Add(4, 30, ColorConst.Forth);
      //series1.Add(4, 5, ColorConst.Fifth);
      //series1.Add(4, 40, ColorConst.Sixth);
      //series1.Add(4, 25, ColorConst.Seventh);
      //series1.Add(4, 10, ColorConst.Eight);
      //series1.Add(4, 23, ColorConst.Nineth);
      //series1.Add(4, 27, ColorConst.Tenth);
      //series1.MultiBar = MultiBars.SelfStack;


      //drawAt = new Steema.TeeChart.Drawing.PointDouble(series1.XValues.Maximum, 20);


      tChart1.Axes.Left.Automatic = false;
      tChart1.Axes.Left.AutomaticMaximum = false;
      tChart1.Axes.Left.AutomaticMinimum = false;

      tChart1.Axes.Left.Maximum = 200;
      tChart1.Axes.Left.Minimum = -30;

      tChart1.Axes.Bottom.Automatic = false;
      tChart1.Axes.Bottom.AutomaticMaximum = false;
      tChart1.Axes.Bottom.AutomaticMinimum = false;

      tChart1.Axes.Bottom.Maximum = 10;
      tChart1.Axes.Bottom.Minimum = 0;

      //tChart1.GetAxisLabel += tChart1_GetAxisLabel;
    }

    void tChart1_GetAxisLabel(object sender, GetAxisLabelEventArgs e)
    {
      double temp = Convert.ToDouble(e.LabelText);

      if (sender.Equals(tChart1.Axes.Left))
      {
        temp += drawAt.Y;
      }
      else if (sender.Equals(tChart1.Axes.Bottom))
      {
        temp += drawAt.X;
      }

      e.LabelText = temp.ToString();
    }

    private void CreateChart()
    {
      tChart1 = new TChart();
      tChart1.Dock = DockStyle.Fill;
      tblPanel.Controls.Add(tChart1, 0, 1);
      tblPanel.Dock = DockStyle.Fill;
    }

    private void btnModify_Click_1(object sender, EventArgs e)
    {
      tChart1.ShowEditor();
    }
  }

  public class ColorConst
  {
    public static readonly Color First = Color.FromArgb(219, 219, 219);
    public static readonly Color Second = Color.FromArgb(222, 216, 218);
    public static readonly Color Third = Color.FromArgb(184, 186, 216);
    public static readonly Color Forth = Color.FromArgb(209, 185, 189);
    public static readonly Color Fifth = Color.FromArgb(142, 149, 189);
    public static readonly Color Sixth = Color.FromArgb(201, 147, 151);
    public static readonly Color Seventh = Color.FromArgb(90, 102, 166);
    public static readonly Color Eight = Color.FromArgb(174, 82, 98);
    public static readonly Color Nineth = Color.FromArgb(22, 45, 160);
    public static readonly Color Tenth = Color.FromArgb(155, 0, 69);

    public static readonly List<Color> List = new List<Color>() { First, Second, Third, Forth, Fifth, Sixth, Seventh, Eight, Nineth, Tenth };
  }
}
This gives me the attached image (the points series here just a placeholder for a second series):
chandran.PNG
chandran.PNG (15.97 KiB) Viewed 14809 times
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply