Chartjs-Razor chart.js labels/data not in sync

0๐Ÿ‘

I had to convert the comma in decimal Totalen to a period!

   @foreach (var m in Model.Grafieks)
        {
            @:Maanden.push("@m.maand" + "-" + "@m.jaar");
           <text>bedrag = parsePotentiallyGroupedFloat("@m.Total");</text> 
            @:Totalen.push(bedrag);
        }   
    function parsePotentiallyGroupedFloat(stringValue) {
            stringValue = stringValue.trim();
            var result = stringValue.replace(/[^0-9]/g, '');
            if (/[,\.]\d{2}$/.test(stringValue)) {
                result = result.replace(/(\d{2})$/, '.$1');
            }
            return parseFloat(result);
        }

The function "parsePotentiallyGroupedFloat" is from here: Convert String with Dot or Comma as decimal separator to number in JavaScript

Leave a comment