How can I present in minutes:seconds the value of a Tooltip that is given in seconds?

Asked

Viewed 38 times

-1

The value of the Y series is given in seconds, but I need to present in the tooltip in minutes:seconds. Example: Value in seconds= 320. Value to be displayed in tooltip= 05:20.

I made a script to change the format, calculating the quotient and rest, turning to string and passing to tooptip, but the result is always Nan. How could I format this value to display on tooltip Os 05:20?

My application is c# with MVC standard. Charts are rendered by Highcharts.

@{var chartOptions4 = new Highcharts
                    {
                        Title = new Title
                        {
                            Text = "Setting Time"
                        },
                        XAxis = new List<XAxis>
                            {
                            new XAxis
                            {
                                Categories = ViewData["datas_saida_resf_prod"] as List<string>
                            }
                        },
                        YAxis = new List<YAxis>
                        {
                            new YAxis
                            {
                                Labels = new YAxisLabels
                                {
                                    Formatter = "formatYAxis1"
                                }
                            }
                        },
                        Tooltip = new Tooltip
                        {
                            HeaderFormat = "<b>{point.x}</b><br>",
                            PointFormatter = "formatToolTip"
                        },
                        Series = new List<Series>
                        {
                            new LineSeries
                            {
                                Name = "Normal T.I.",
                                Data = @ViewData["lista_normalTI"] as List<LineSeriesData>
                            },
                            new LineSeries
                            {
                                Name = "Normal T.F.",
                                Data = @ViewData["lista_normalTF"] as List<LineSeriesData>
                            },
                            new LineSeries
                            {
                                Name = "Moído T.I.",
                                Data = @ViewData["lista_moidoTI"] as List<LineSeriesData>
                            },
                            new LineSeries
                            {
                                Name = "Moído T.F.",
                                Data = @ViewData["lista_moidoTF"] as List<LineSeriesData>
                            }
                                                                                                                                                                                                                                                                                                                                              }
                    };
                    chartOptions4.ID = "chart4";
                    var renderer4 = new HighchartsRenderer(chartOptions4);
                    }

                    @Html.Raw(renderer4.RenderHtml())

Script:

 function formatToolTip() {
            var quociente, resto;
            quociente = Math.floor((this.value / 60), 0);
            resto = Math.round(((this.value / 60) - quociente) * 60);
            var valor = (Math.floor((this.value / 60), 0)).toString() + ":" + (Math.round(((this.value / 60) - quociente) * 60)).toString();

            var result = this.series.name + ':' + valor;
            return result;
        }

The result of this code is: inserir a descrição da imagem aqui

  • Why don’t you already pass this formatted information? your question is about javascript or C#?

  • Because, as far as I know, Lineseriesdata only accepts the double value.

  • So I thought of formatting in javascript itself

1 answer

-2

Just use this.y in place of this.value.

  • 1

    @Augustovasques thank you, I had not noticed that when choosing a signage was automatically made a comment rs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.