TeeChart .NET For Blazor Getting series y position in pixels

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
dynamicrisk
Newbie
Newbie
Posts: 26
Joined: Thu Apr 06, 2023 12:00 am

TeeChart .NET For Blazor Getting series y position in pixels

Post by dynamicrisk » Thu Aug 29, 2024 3:35 pm

Hello,

I am trying calculate the y position in pixels of a series that is using a custom axis. Using the axis.CalcYPosValue is always returning 0. Is there a way to do this with Custom axes?

Code: Select all

        Axis anomaliesAxis = new Axis(false, false, mChart.Chart);
        anomaliesAxis.Title.Text = "Clock";
        anomaliesAxis.Inverted = true;
        anomaliesAxis.SetMinMax(0, 12);
        anomaliesAxis.StartPosition = 10;
        anomaliesAxis.EndPosition = 100;

foreach (Series s in mChart.Series)
{
        // scatter series
            s.FillSampleValues();
            for (int i = 0; i < 101; i++)
            {
                Random rnd = new Random();
                if(i == 0)
                {
                    s.XValues.Value[i] = 0;
                }
                else
                {
                    s.XValues.Value[i] = rnd.NextDouble() * 1000;
                }
                s.YValues.Value[i] = rnd.NextDouble() * 12;
            }

            s.CustomVertAxis = anomaliesAxis;
            mChart.Axes.Custom.Add(anomaliesAxis);
}

int boxCounter = 0;

foreach (double valueX in aChart.Series[0].XValues.Value)
{
    if (boxCounter > 24)
    {
        break;
    }

    double valueY = aChart.Series[0].YValues.Value[boxCounter];
    int x = rndX.Next(0, 50);
    int y = rndY.Next(0, 100);

    Axis axis = aChart.Series[0].CustomVertAxis;

    int y1 = axis.CalcYPosValue(valueY);  // --> always returns 0

boxCounter++; 
}
Thanks

Edu
Newbie
Newbie
Posts: 40
Joined: Tue Nov 28, 2023 12:00 am

Re: TeeChart .NET For Blazor Getting series y position in pixels

Post by Edu » Fri Aug 30, 2024 10:37 am

Hello,
I am trying calculate the y position in pixels of a series that is using a custom axis. Using the axis.CalcYPosValue is always returning 0. Is there a way to do this with Custom axes?
Yes, your code works well! However, it's important to note that the chart only has access to certain details, such as coordinates, after it has finished drawing. To ensure your code functions as expected, consider placing it within the mChart.AfterDraw event, a button click event, or other similar triggers. This will allow the chart to fully render before your code executes, ensuring everything works as intended.

Here's an example:

Code: Select all

        private void TChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.IGraphics3D g)
        {
            int boxCounter = 0;

            foreach (double valueX in points.XValues.Value)
            {
                if (boxCounter > 24)
                {
                    break;
                }

                double valueY = points.YValues.Value[boxCounter];

                int y1 = anomaliesAxis.CalcYPosValue(valueY); // Returns proper data :)

                boxCounter++;
            }
        }
If there's anything else I can assist you with, feel free to let me know!

Best regards,
Edu
Edu
Steema Support

dynamicrisk
Newbie
Newbie
Posts: 26
Joined: Thu Apr 06, 2023 12:00 am

Re: TeeChart .NET For Blazor Getting series y position in pixels

Post by dynamicrisk » Thu Sep 05, 2024 3:04 pm

Hi Edu,

mChart.AfterDraw += TChart_AfterDraw doesnt trigger private void TChart_AfterDraw(object sender, Steema.TeeChart.Drawing.IGraphics3D g).

Will a blazor chart trigger an event in .NET?

I have also tried getting a javascript function to trigger but this is not working either.

Code: Select all

customCode.Add($"{aChart.Export.Image.JScript.ChartName}.afterdraw = function()");
customCode.Add("{");
customCode.Add("console.log('draw function triggered.')");
customCode.Add("DotNet.invokeMethodAsync('TeeChartOnBlazor', 'ReturnArrayAsync')");
customCode.Add(".then(result =>");
customCode.Add("{");
customCode.Add("console.log(result)");
customCode.Add("});");
customCode.Add("}");
Any help would be appreciated.
Thanks,

Edu
Newbie
Newbie
Posts: 40
Joined: Tue Nov 28, 2023 12:00 am

Re: TeeChart .NET For Blazor Getting series y position in pixels

Post by Edu » Fri Sep 06, 2024 10:38 am

Hello,
customCode.Add($"{aChart.Export.Image.JScript.ChartName}.afterdraw = function()");
The function you're trying to use is called ondraw. Maybe this change alone fixes the issues you're encountering.

For example:

Code: Select all

        customCode.Add($"{chartName}.ondraw = function()");
        customCode.Add("{");
        customCode.Add("console.log('hello tchart users')");
        customCode.Add("}");
If you want to calculate pixels from values, you should do that through js and not .NET when working with Blazor Charts.

If there's anything else I can help you with, please let me know.

Regards,
Edu
Edu
Steema Support

Post Reply