how to replace comma with dot

deep sodhi

I am having comma values inside my json and i want when i get those values i get them in dot so basically I want to convert my comma values into dot values..my json looks like and its always fixed that i will get comma values at val003. I know something to do like var new = new.replace(/,/g, '.') . but how can i specify my val003 here for the conversion. Thank you in advance

My html

<!doctype html>

<html>

<head>

    <meta charset="UTF-8">
    <meta content="utf-8" http-equiv="encoding">
      <div id="below">
        <div id="chart"></div>
    </div>
    <script>
        var jsonURL = 'avb.json';
        var myData = [];
        var fliterdata = [];
        var tempdata = [];
        var selectop = "";
        var selectDate = false;
        var chartType = chartType || 'bar';

        function filterJSON(json, key, value) {
            var result = [];
            for (var foo in json) {
                var extractstr = json[foo][key] ;
                extractstr=String(extractstr);

                if (extractstr.slice(3)== value) {

                    result.push(json[foo]);

               }
            }
            return result;
        }
        function selectValue(d) {    
            switch (selectop) { //d object select particular value for Y axis
                case "01":
                    return d.val001;
                    break;
                case "02":
                    return d.val002;
                    break;
                case "03":
                    return d.val003;
                    break;
                case "04":
                    return d.val004;
                    break;
               default:
                    //console.log("default");
                    return d.val001;
            }


        }

      var line = d3.svg.line()
                .x(function(d) {
                    return xScale(d.date);
                })
                .y(function(d) {
                    return yScale(selectValue(d));
                })
                .interpolate("monotone")
                .tension(0.9);




            yScale.domain([0, d3.max(tempData, function(d) {
                return +selectValue(d);
            })]);

            var svg = d3.select('#chart').append('svg')
                    .attr("width", width + margin.left + margin.right)
                    .attr("height", height + margin.top + margin.bottom)
                    .append("g")
                    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");


            if (chartType == 'bar') {
                svg
                        .selectAll(".bar") //makes bar
                        .data(tempData)
                        .enter().append("rect")
                        .attr("class", "bar")
                        .style("fill", "teal")
                        .attr("x", function(d) {
                            return xScale(d.date);
                        }).attr("width", xScale.rangeBand())
                        .attr("y", function(d) {


                            return yScale(selectValue(d));
                        }).attr("height", function(d) {

                    console.log("as", d.value);
                    return height - yScale(selectValue(d));
                })
            }

            if (chartType == 'line') {
                svg.append("path") // Add the line path.
                        .data(tempData)
                        .attr("class", "line")
                        .attr("d", line(tempData));
            }

        }
        d3.json(jsonURL, function(data) {

            myData = data; //data from json in mydata
           d.val003.replace(",",".")
            myData.forEach(function(d) {

                d.date = new Date(d.date);
                d.date = new Date(d.date + " UTC");

            });

            $("#listbox").on("click", function() {

                var key = $(this).val();
                console.log("key:", key);
                var value = $('#listbox option:selected').text();
                console.log("vaue:", value);

                selectop = String(key);

                selectop = selectop.slice(-2);
                console.log("mydata: ", myData);
                console.log("selectops:", selectop);

                fliterdata = filterJSON(myData, key, value); //selected value from user and picks the whole element that contains that attribute

                console.log("fliterdata: ", fliterdata);
                tempData = fliterdata; //graph made by temp data
                if (selectDate)
                    render(true);
            });
        });

        function selectChartType(type) {
            chartType = type;
            render(true);
        }
    </script>
    </body>
</div>
</body>
</html>
Kinjal Gohil

Try this,

return d.val003.toString().replace(",",".");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Replace ,(comma) by .(dot) and .(dot) by ,(comma)

From Dev

How to replace number dot (.) with a comma (,) using java

From Dev

How to replace dot with comma in price format in php

From Dev

How can i replace dot with comma in iReport?

From Dev

Replace dot with comma on SELECT

From Dev

Need to replace "comma" with 'dot'

From Dev

Replace comma with dot in a input Javascript

From Dev

replace comma to dot in perl array

From Dev

javascript replace comma with dot / paypal

From Dev

Replace comma with dot in a input Javascript

From Dev

match float with comma and then replace comma with dot?

From Dev

Replace a dot with a comma inside a jQuery template

From Dev

replace comma with dot in scientific notation in r

From Dev

Replace comma with a dot while typing jQuery

From Dev

In Java, convert the dot to comma in DecimalFormat replace method

From Dev

Replace a dot with a comma inside a jQuery template

From Dev

Decimalformat: unwanted replace of dot with comma in JTable

From Dev

Replace dot character once entered by a comma in jquery

From Dev

Best way to replace comma with a dot jquery

From Dev

How to replace dot in linux

From Dev

How to replace dot in linux

From Dev

Replace the decimal dot with a comma on an axis in D3?

From Dev

Replacing comma by dot only in numbers in a texteditor using search and replace function

From Dev

How to make dot and comma sensation in GridView Textbox?

From Dev

how to replace many occurrences of comma by single comma

From Dev

how to replace many occurrences of comma by single comma

From Dev

How to replace every dot in string with a "/" in JavaScript

From Dev

Vim - how to replace a space after dot with a newline?

From Dev

How to accept both dot and comma as a decimal separator with WTForms?

Related Related

  1. 1

    Replace ,(comma) by .(dot) and .(dot) by ,(comma)

  2. 2

    How to replace number dot (.) with a comma (,) using java

  3. 3

    How to replace dot with comma in price format in php

  4. 4

    How can i replace dot with comma in iReport?

  5. 5

    Replace dot with comma on SELECT

  6. 6

    Need to replace "comma" with 'dot'

  7. 7

    Replace comma with dot in a input Javascript

  8. 8

    replace comma to dot in perl array

  9. 9

    javascript replace comma with dot / paypal

  10. 10

    Replace comma with dot in a input Javascript

  11. 11

    match float with comma and then replace comma with dot?

  12. 12

    Replace a dot with a comma inside a jQuery template

  13. 13

    replace comma with dot in scientific notation in r

  14. 14

    Replace comma with a dot while typing jQuery

  15. 15

    In Java, convert the dot to comma in DecimalFormat replace method

  16. 16

    Replace a dot with a comma inside a jQuery template

  17. 17

    Decimalformat: unwanted replace of dot with comma in JTable

  18. 18

    Replace dot character once entered by a comma in jquery

  19. 19

    Best way to replace comma with a dot jquery

  20. 20

    How to replace dot in linux

  21. 21

    How to replace dot in linux

  22. 22

    Replace the decimal dot with a comma on an axis in D3?

  23. 23

    Replacing comma by dot only in numbers in a texteditor using search and replace function

  24. 24

    How to make dot and comma sensation in GridView Textbox?

  25. 25

    how to replace many occurrences of comma by single comma

  26. 26

    how to replace many occurrences of comma by single comma

  27. 27

    How to replace every dot in string with a "/" in JavaScript

  28. 28

    Vim - how to replace a space after dot with a newline?

  29. 29

    How to accept both dot and comma as a decimal separator with WTForms?

HotTag

Archive