Specific custom y axis labels

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
TomAgos
Newbie
Newbie
Posts: 5
Joined: Thu Jan 16, 2025 12:00 am

Specific custom y axis labels

Post by TomAgos » Tue Jan 28, 2025 12:13 pm

Hey

we are adding few FastLines to the chart, and for every FastLine we create y axis and attach him to it.
every y axis have Min and Max using the 'SetMinMax' method.
i want only 2 labels on every y axis:
1. the minimum value at the bottom
2. the maximum value at the top

this is what i tried:

Code: Select all

       
       private Axis CreateCustomYAxis(SignalModel signal, double relativePosition)
       {
           var color = ChartDataToZData.MColorToDColor(signal.Color);
           var yAxis = new Axis
           {
               Visible             = false,
               Horizontal          = false,
               Grid                = { Visible = false },
               Labels              = { Font = { Color = color } },
               AxisPen             = { Color = color, Visible = true },
               Ticks               = { Color = color },
               RelativePosition    = relativePosition
           };            

           yAxis.SetMinMax(signal.MinOrFactor, signal.MaxOrOffset);

           yAxis.GetAxisDrawLabel += YAxis_GetAxisDrawLabel;
           return yAxis;
       }
       
         private void YAxis_GetAxisDrawLabel(object sender, GetAxisDrawLabelEventArgs e)
        {
            if (sender is Axis axis) // Cast sender to Axis
            {                
                if (e.LabelValue != axis.Minimum && e.LabelValue != axis.Maximum)                
                    e.Text = ""; // Hide all other labels                
            }
        }       
       
this works fine most of the time. but in some Minimum and maximum values i cant see the minimum label.
for example, when the minimum of the axis is -500 and the maximum is 500, no minimum label.

any suggestions?

Marc
Site Admin
Site Admin
Posts: 1285
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Specific custom y axis labels

Post by Marc » Tue Jan 28, 2025 1:33 pm

Hello,

There are different ways of approaching this but adding customised labels for this controlled intention, rather than a callback, may be an easier way:

Code: Select all

private Axis CreateCustomYAxis(SignalModel signal, double relativePosition)
    {
      var color = ChartDataToZData.MColorToDColor(signal.Color);
      var yAxis = new Axis
      {
        Visible = false,
        Horizontal = false,
        Grid = { Visible = false },
        Labels = { Font = { Color = color } },
        AxisPen = { Color = color, Visible = true },
        Ticks = { Color = color },
        RelativePosition = relativePosition
      };

      yAxis.SetMinMax(signal.MinOrFactor, signal.MaxOrOffset);
      AddCustomLabels(signal.MinOrFactor, signal.MaxOrOffset);

      return yAxis;
    }

    private void AddCustomLabels(double aMin, double aMax)
    {
      tChart1.Axes.Custom[0].Labels.Items.Clear();
      (tChart1.Axes.Custom[0].Labels.Items.Add(aMax, aMax.ToString())).Font.Size = 16;  //optional text enhancement
      tChart1.Axes.Custom[0].Labels.Items.Add(aMin, aMin.ToString());
    }


Regards,
Marc Meumann
Steema Support

TomAgos
Newbie
Newbie
Posts: 5
Joined: Thu Jan 16, 2025 12:00 am

Re: Specific custom y axis labels

Post by TomAgos » Wed Jan 29, 2025 7:42 am

This doesnt work:

Image

i hope the image is working..
if not: i still see all the labels... and the minimum and maximum.
and at the first y axis that i add, i dont see any labels

TomAgos
Newbie
Newbie
Posts: 5
Joined: Thu Jan 16, 2025 12:00 am

Re: Specific custom y axis labels

Post by TomAgos » Wed Jan 29, 2025 8:20 am

i also need to update the labels when zooming in and out, and when panning.
the axis label should display the new maximum and minimum according to the zoom and panning, so this should update in run time. ideas?

Marc
Site Admin
Site Admin
Posts: 1285
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Specific custom y axis labels

Post by Marc » Wed Jan 29, 2025 10:51 am

The Chart needs to have calculated the axes before settings items will work, normally a start, once only, repaint resolves that. But anyway if you want to zoom the axes and require a change of labels, then the labels will require updating and the callback should be used. I'll modify the example and post the sample code up here.

Regards,
Marc
Steema Support

Marc
Site Admin
Site Admin
Posts: 1285
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Specific custom y axis labels

Post by Marc » Wed Jan 29, 2025 12:43 pm

There's a TeeChart bug here. Custom axes stats don't correctly update after a zoom (like they do after a scroll/pan). We'll fix it. Thanks for reporting the issue.

https://www.steema.com/bugs/show_bug.cgi?id=2758

Regards,
Marc
Steema Support

Post Reply