-1

I am new in PHP and Javascript. i need to create pi chart from JSON which should be read from URL.

I tried to create pi chart to directly given json data and it works. My code is given below :-

<!DOCTYPE html>    
<html>
<head>
<title></title>
<link href="http://cdn-na.infragistics.com/igniteui/2018.1/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" />
<link href="http://cdn-na.infragistics.com/igniteui/2018.1/latest/css/structure/infragistics.css" rel="stylesheet" />
<script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"> 
</script>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
<script src="http://cdn-na.infragistics.com/igniteui/2018.1/latest/js/infragistics.core.js"></script>
<script src="http://cdn-na.infragistics.com/igniteui/2018.1/latest/js/infragistics.dv.js"></script>
</head>
<body>
<style type="text/css">
     #chart { position: relative;
        float: left;
        margin-right: 10px;
        margin-bottom: 10px;
}   
</style>
<div id="chart"></div>
<script type="text/javascript">
$(function () {
        var data = [
            { "Badge_SubDomain": "Data Architecture", "count": "1333"},
            { "Badge_SubDomain": "Data Integration", "count": "849"},
            { "Badge_SubDomain": "Data Platform", "count": "250"},
                 ];

        $("#chart").igPieChart({
            width: "435px",
            height: "435px",
            dataSource: data, 
            dataValue: "count",
            dataLabel: "Badge_SubDomain",
            labelsPosition: "bestFit" });
});
</script>
</body>
</html>

The JSON data from the URL is :-

[{  
    "Domain":"Artificial Intelligence",
    "Count":"46"
}, {  
    "Domain":"Data Architecture",
    "Count":"21"
}, {  
    "Domain":"Data Science",
    "Count":"50"
}]

I need to read data from URL instead of direct giving value. The 'Count' in JSON data is in string format and it needs to change float format for plotting pi chart. How can i change code for it?

4
  • 1
    A π-Chart or a Pie-Chart? Commented May 22, 2018 at 12:43
  • 1
    "I need to read data from URL instead of direct giving value" Okay, so what have you tried to accomplish this? Commented May 22, 2018 at 12:45
  • 2
    Possible duplicate of Pie chart creating from JSON Data in Javascript Commented May 22, 2018 at 12:53
  • 1
    I'm not sure why you posted the same question twice, but you need to delete at least one of them Commented May 22, 2018 at 12:53

1 Answer 1

-1
$.get("url", function(data, status){ 

var data = [ {"Domain":"Artificial Intelligence","Count":"46"}, {"Domain":"Data Architecture","Count":"21"}, {"Domain":"Data Science","Count":"50"}, ]

finalArray = data.map(data => parseFloat(data.Count));

}); Result = [46, 21, 50]

Sign up to request clarification or add additional context in comments.

1 Comment

The user posted the same question twice. I'd post your answer on the first one, this one will almost certainly be closed/deleted. See the dupe link in the comment on the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.