Page 1 of 1

Specific custom y axis labels

Posted: Tue Jan 28, 2025 12:13 pm
by 21099317
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?

Re: Specific custom y axis labels

Posted: Tue Jan 28, 2025 1:33 pm
by Marc
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

Re: Specific custom y axis labels

Posted: Wed Jan 29, 2025 7:42 am
by 21099317
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

Re: Specific custom y axis labels

Posted: Wed Jan 29, 2025 8:20 am
by 21099317
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?

Re: Specific custom y axis labels

Posted: Wed Jan 29, 2025 10:51 am
by Marc
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

Re: Specific custom y axis labels

Posted: Wed Jan 29, 2025 12:43 pm
by Marc
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