1

I am working with C# windows from application. I am using TeeChart for .net v3 to plot chart.I am able to create multiple Y-axis with different color for each one as shown in below image. enter image description here Now i am able to display the axis with difftent color but i want to assign the same axis color to the scale of its axis also. Please help me what property i need to use.

one more problem is If i have multiple axis then it is taking to much space on chart to create separate axis for each. I want assign the scale of axis horizontally not like the one i am getting now. Please can any one help me please what properties i need to use. I want to represent scale and axis as shown in below image. scale

Thanks in advance.

reddy
  • 183
  • 4
  • 15

1 Answers1

1

I have made a simple code where I have achieved set same scale for each custom axis I have drawn and place the all axes in a correct position automatically. I think you can use similar code as next to try to achieve as you want:

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

        private DataSet GetData()
        {
            DataSet TeeDataSet = new DataSet();
            DateTime dt = DateTime.Today;
            DataTable TeeDataTable = new DataTable("DataTable1");
            DataColumn xval = new DataColumn("DateTime", typeof(DateTime));
            DataColumn yval = new DataColumn("SystemName", typeof(double));

            TeeDataTable.Columns.Add(xval);
            TeeDataTable.Columns.Add(yval);
            Random rnd = new Random();
            for (int i = 0; i < 10; i++)
            {
                DataRow newRow = TeeDataTable.NewRow();
                newRow[xval] = dt;
                newRow[yval] = rnd.Next(100);
                TeeDataTable.Rows.Add(newRow);
                dt = dt.AddMonths(1);
            }
            TeeDataSet.Tables.Add(TeeDataTable);
            return TeeDataSet;
        }
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Header.Visible = false;
            tChart1.Legend.Alignment = LegendAlignments.Bottom;
            tChart1.Legend.CheckBoxes = true;
            for (int i = 0; i < 5; i++)
            {
                new Steema.TeeChart.Styles.Line(tChart1.Chart);
                tChart1[i].Title = "SystemName";
                tChart1[i].DataSource = GetData();//Add values using DataSource
                tChart1[i].XValues.DataMember = "DateTime";
                tChart1[i].XValues.DateTime = true;
                tChart1[i].XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
                tChart1[i].YValues.DataMember = "SystemName";
                tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                tChart1[i].CustomVertAxis = tChart1.Axes.Custom[i];
                tChart1.Axes.Custom[i].AxisPen.Color = tChart1[i].Color;
                tChart1.Axes.Custom[i].Grid.Visible = false;

                tChart1.Axes.Custom[i].PositionUnits = PositionUnits.Pixels;
            }

            tChart1.Panel.MarginUnits = PanelMarginUnits.Pixels;
            tChart1.Panel.MarginTop = 20;
            tChart1.Draw();
            PlaceAxes(0, 0, 0, 0, 0);
            tChart1.AfterDraw += new PaintChartEventHandler(tChart1_AfterDraw);
            tChart1.ClickLegend += new MouseEventHandler(tChart1_ClickLegend);
            tChart1.Draw();
        }

        void tChart1_ClickLegend(object sender, MouseEventArgs e)
        {
            tChart1.Draw();
        }

        void tChart1_AfterDraw(object sender, Graphics3D g)
        {
            PlaceAxes(0, 0, 0, 0, 0);
        }

        private void PlaceAxes(int nSeries, int NextXLeft, int NextXRight, int MargLeft, int MargRight)
        {
            const int extraPos = 12;
            const int extraMargin = 60;
            //Variable 
            int MaxLabelsWidth;
            int lenghtTicks;
            int extraSpaceBetweenTitleAndLabels;
            foreach (Steema.TeeChart.Styles.Line s in tChart1.Series)
            {
                if (s.Active)
                {
                    s.CustomVertAxis.Visible = true;
                    s.CustomVertAxis.SetMinMax(tChart1[0].YValues.Minimum, tChart1[0].YValues.Maximum);
                    MaxLabelsWidth = s.CustomVertAxis.MaxLabelsWidth();
                    lenghtTicks = s.CustomVertAxis.Ticks.Length;
                    extraSpaceBetweenTitleAndLabels = (s.CustomVertAxis.Title.Width);//- tChart1.Axes.Custom[nSeries].MaxLabelsWidth());
                    if (s.CustomVertAxis.Title.Visible)
                    {
                        s.CustomVertAxis.RelativePosition = NextXLeft;
                        NextXLeft = NextXLeft - (MaxLabelsWidth + lenghtTicks + extraSpaceBetweenTitleAndLabels + extraPos);
                        MargLeft = MargLeft + extraMargin;
                    }

                    else
                    {
                        s.CustomVertAxis.RelativePosition = NextXLeft;
                        NextXLeft = NextXLeft - (MaxLabelsWidth + lenghtTicks + extraPos);
                        MargLeft = MargLeft + extraMargin;
                    }

                    tChart1.Panel.MarginLeft = MargLeft;
                    tChart1.Panel.MarginRight = MargRight;

                }
                else
                {
                    s.CustomVertAxis.Visible = false;
                }
            }
        }

Could you tell us if previous code works in your end? If you have any problems, please let me know.

I hope will helps.

Thank you,

Sandra Pazos
  • 843
  • 5
  • 10
  • Thanks for your replay. I am not working with data base, I am getting data from sensors directly and updating chart. If i have three sensors connected then it will create axis for those three with assigned color. I am not using your code to draw axis. The above code i have posted working perfectly. I have added little bit of code for initialization of chart may be you can see. if you need more info please ask me. – reddy Mar 05 '13 at 13:35
  • 1
    Thanks for information. The modification you have done to me, doesn't help me, but I have modified my code, because series gets the data from DataSet and it works fine for me. I think you can use some conditions, methods or properties I have added in my code and apply it in your code, to try achieve it works in your end. If my suggested code doesn't help you, would be very grateful if you can send us a simple example of code where the problem appears, because we can reproduce exactly here your problem and try to find a good solution for you. Thanks, – Sandra Pazos Mar 06 '13 at 13:35
  • Can you any idea about which property i need to use to change the color of axis scale letters. – reddy Mar 07 '13 at 10:10
  • 1
    Hello reddy, If you want modify the color of labels you need change font color property of labels because letter have the same color of Axes. You can do something as next code: axis.Labels.Font.Color = axis].AxisPen.Color; axis.Ticks.Color = axis.AxisPen.Color; axis.MinorTicks.Color = axis.AxisPen.Color; Could you tell us if previous lines of code works in your end? – Sandra Pazos Mar 07 '13 at 16:28