How to change legend name and one grid for all axis.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
biji
Newbie
Newbie
Posts: 35
Joined: Wed Jul 02, 2008 12:00 am

How to change legend name and one grid for all axis.

Post by biji » Fri Nov 08, 2013 1:20 pm

Hi,

I am trying to create multiple y-axis with common x-axis. I have used the example code from tutorial, i am able to succeed to create multiple axis and adding series to each line. for example.

Code: Select all

 Line line1 = new Line();           
  Line line2 = new Line();

 tChart1.Series.Add(line1);            
 tChart1.Series.Add(line2); 
  
I am trying to display legend at bottom of chart , i had tried like this

Code: Select all

 _chart.Legend.Visible = true;
            tChart1.Legend.Visible = true;
            tChart1.Legend.CheckBoxes = true;
            tChart1.Legend.Gradient.Visible = true;
                           
            tChart1.Legend.Gradient.StartColor = Color.LightGray;
            tChart1.Legend.Gradient.MiddleColor = Color.White;
            tChart1.Legend.LegendStyle = LegendStyles.Series;
            tChart1.Legend.Alignment = LegendAlignments.Bottom;
            tChart1.Legend.Shadow.Visible = false;
            tChart1.Legend.ShapeStyle = Steema.TeeChart.Drawing.TextShapeStyle.RoundRectangle;
            tChart1.Legend.HorizMargin = 0;
            tChart1.Legend.VertMargin = 0;
            tChart1.Legend.VertSpacing = 0;

            for (int i = 0; i < tChart1.Series.Count; i++)
            {
                tChart1.Series[i].Active = true;
            }
      
legend was displaying like line1, line2, line3......

how to change those names line1 to some other name? because i want to display sensor name instead of line1,line2....?
I am creating several axis so how to create common grid for all axis?

Thanks,
biji.

biji
Newbie
Newbie
Posts: 35
Joined: Wed Jul 02, 2008 12:00 am

Re: How to change legend name and one grid for all axis.

Post by biji » Mon Nov 11, 2013 10:18 am

Hi,
please can anyone suggest me , the property to change legend name. it was displaying like "line1" . I would like to assign some name to that.

Thanks,
biji

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

Re: How to change legend name and one grid for all axis.

Post by Sandra » Mon Nov 11, 2013 10:57 am

Hello biji,
how to change those names line1 to some other name? because i want to display sensor name instead of line1,line2....?
To Change the Name of your lines, you only must change the title. You can do something as next:

Code: Select all

  private void InitializeChart()
    {
       tChart1.Aspect.View3D = false; 
      Steema.TeeChart.Styles.Line line1 = new Line(tChart1.Chart); 
      Steema.TeeChart.Styles.Line line2 = new Line(tChart1.Chart);
      //Legend
      tChart1.Legend.Alignment = LegendAlignments.Bottom; 
      //Series
      line1.FillSampleValues();
      line2.FillSampleValues(); 
      //Change SeriesName
      line1.Title = "Sensor1";
      line2.Title = "Sensor2";  
}
I am creating several axis so how to create common grid for all axis?
To use multi-axes and customize the grid of it, you can do something as next code:

Code: Select all

  private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      Steema.TeeChart.Axis axis1 = new Axis(tChart1.Chart);
      tChart1.Axes.Custom.Add(axis1);
      axis1.Horizontal = false; 
      Steema.TeeChart.Styles.Line line1 = new Line(tChart1.Chart); 
      Steema.TeeChart.Styles.Line line2 = new Line(tChart1.Chart);
      //Legend
      tChart1.Legend.Alignment = LegendAlignments.Bottom; 
      //Series
      line1.FillSampleValues();
      line2.FillSampleValues(); 
      //Change SeriesName
      line1.Title = "Sensor1";
      line2.Title = "Sensor2"; 
      //Axis
      line1.CustomVertAxis = axis1;
      line2.VertAxis = VerticalAxis.Left;
      axis1.StartPosition = 0;
      axis1.EndPosition = 50;
      axis1.AxisPen.Color = Color.Red;
      axis1.Grid.Color = Color.Red;
      tChart1.Axes.Left.StartPosition = 50;
      tChart1.Axes.Left.EndPosition = 100; 
}
Also is recommendable taking a look in the TeeChartDemo, concretely in All features\Axes to see more examples as you do to work with custom axes and axes.

Could you confirm 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

biji
Newbie
Newbie
Posts: 35
Joined: Wed Jul 02, 2008 12:00 am

Re: How to change legend name and one grid for all axis.

Post by biji » Wed Nov 20, 2013 1:25 pm

Hi sandra,

it works for changing legend name, thanks alot.

but i tried to keep one common grid for all axis. but i didn't succeed. for example i have 8 left vertical Y-axis and one common x-axis. Even If i use this code as you provided in previous reply

Code: Select all

 private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      Steema.TeeChart.Axis axis1 = new Axis(tChart1.Chart);
      tChart1.Axes.Custom.Add(axis1);
      axis1.Horizontal = false; 
      Steema.TeeChart.Styles.Line line1 = new Line(tChart1.Chart); 
      Steema.TeeChart.Styles.Line line2 = new Line(tChart1.Chart);
      //Legend
      tChart1.Legend.Alignment = LegendAlignments.Bottom; 
      //Series
      line1.FillSampleValues();
      line2.FillSampleValues(); 
      //Change SeriesName
      line1.Title = "Sensor1";
      line2.Title = "Sensor2"; 
      //Axis
      line1.CustomVertAxis = axis1;
      line2.VertAxis = VerticalAxis.Left;
      axis1.StartPosition = 0;
      axis1.EndPosition = 50;
      axis1.AxisPen.Color = Color.Red;
      axis1.Grid.Color = Color.Red;
      tChart1.Axes.Left.StartPosition = 50;
      tChart1.Axes.Left.EndPosition = 100; 
}
my problem is i can try like this for example the below line

Code: Select all

axis.Grid.Visible = true;
but if i use this code for one axis and for the reaming axis i can set this to false,

Code: Select all

axis.Grid.Visible = false;
then its working but here i have small problem some times if i don't have any value from sensor which i have set axis.grid.visible property is true then it won't create that vertical axis at that time i am loosing grid. how to prevent this and to keep one common grid for entire chart without depending axis.
Can you help me with this problem.

If you don't understand than i will attach with images. don't hesitate to ask me if u need more information

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

Re: How to change legend name and one grid for all axis.

Post by Sandra » Fri Nov 22, 2013 3:10 pm

Hello biji,

I think you can enable/desable the axis when you have data or not in your sensor. You can disable the axis setting its property visible to true or false as I have made in next line of code:

Code: Select all

axis1.visible= false; 
If you do it, you can achieve the axis is invisible when there isn't data in the sensor. Next code demonstrate as work it:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      Steema.TeeChart.Axis axis1 = new Axis(tChart1.Chart);
      tChart1.Axes.Custom.Add(axis1);
      axis1.Horizontal = false;
      Steema.TeeChart.Styles.Line line1 = new Line(tChart1.Chart);
      Steema.TeeChart.Styles.Line line2 = new Line(tChart1.Chart);
      //Legend
      tChart1.Legend.Alignment = LegendAlignments.Bottom;
      //Series
      line1.FillSampleValues();
      line2.FillSampleValues();
      //Change SeriesName
      line1.Title = "Sensor1";
      line2.Title = "Sensor2";
      //Axis
      line1.CustomVertAxis = axis1;
      line2.VertAxis = VerticalAxis.Left;
      axis1.StartPosition = 0;
      axis1.EndPosition = 50;
      axis1.AxisPen.Color = Color.Red;
      axis1.Visible = false; 
      axis1.Grid.Color = Color.Red;
      tChart1.Axes.Left.StartPosition = 50;
      tChart1.Axes.Left.EndPosition = 100;
      axis1.Grid.Visible = false; 
      button1.Click +=button1_Click;
    }

    void button1_Click(object sender, EventArgs e)
    {
      tChart1.Axes.Custom[0].Visible = true; 
    }
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

Post Reply