javascript - d3 v4 js guage chart needle value shows between 0 to 180 , i want to show 0 to 10000 -


hi guys i'm new d3 js, struck in gauge chart in d3v4, have done gauge chart works fine problem needle values shows between 0 180, want show values between 0 10000. have json file {"total":5520,"red":2000,"green":5000,"yellow":3000 }, me , in advance. code is:

  <head>     <link rel="stylesheet" href="style.css">     <script src="script.js"></script>   </head>    <body>   <h1>guage</h1> <div id="g1"></div>  <script src="https://d3js.org/d3.v4.min.js"></script>  <script> var width = 400; var height = 500;  var padding = 100;  var gaugemaxvalue = 10000;  margin = {           top: 20,           right: 20,           bottom: 30,           left: 20         };  var svg = d3.select( "#g1" )   .append( "svg" )   .attr( "width", width )   .attr( "height", height );  var arc = d3.arc()   .innerradius( 60 )   .outerradius( 140 )   .cornerradius( 5 )   .padangle( 0 );  // array of colors colors = [ "#ff0000", "#ffa500", "#00ff00" ];  // colors = [ "#ff0000","#00ff00","#ffa500"];  // fetch json data. in here build guage d3.json("data.json", function(error, data) {      // console.log(data.values())       // initialize pie chart     var pie = d3.pie()         .startangle( (-1*math.pi) / 2 )         .endangle( math.pi / 2 )      .sort(null)         .value( function( d ) {              return  d;         } );      // draw arcs. 1 each color     var arcs = svg.selectall( '.arc' )         .data( pie( [data.red,data.yellow,data.green]) )         .enter()         .append( 'path' )     .attr( "d", arc )         .attr( "transform", "translate(200,200)" )         .style( "fill", function( d ,i) {       // alert(i)             return colors[i]         } );       svg.append("text")              .attr("text-anchor", "middle")  // makes easy centre text transform applied anchor             .attr("transform", "translate("+ (padding/2) +","+(height/2.5)+")")  // text drawn off screen top left, move down , out , rotate             .text(function(){                     return "$ "+0;                });      svg.append("text")              .attr("text-anchor", "middle")  // makes easy centre text transform applied anchor             .attr("transform", "translate(366.889,200)")             .text(function(){                     return "$ "+gaugemaxvalue;                });      svg.append("text")              .attr("text-anchor", "middle")  // makes easy centre text transform applied anchor             .attr("transform", "translate("+ (padding/.5) +","+(height/8.5)+")")             .text(function(){                     return "$ "+gaugemaxvalue/2;                });      svg.append("text")              .attr("text-anchor", "middle")  // makes easy centre text transform applied anchor             .attr("transform", "translate("+ (padding/.5) +","+(height/14)+")")             .attr("font-size",20)             .text("sum of total amount");      svg.append("text")              .attr("text-anchor", "middle")  // makes easy centre text transform applied anchor             .attr("transform", "translate("+ (padding/.5) +","+(height/2.2)+")")             .text(function(){                     return "$ "+data.total;                });       // set needle        needlelen = 60;     needleradius = 10;     percent = .65;      thetarad =  percent / 2;      centerx = 0;     centery = 0;      topx = centerx - needlelen * math.cos(thetarad);     topy = centery - needlelen * math.sin(thetarad);      leftx = centerx - needleradius * math.cos(thetarad - math.pi / 2);     lefty = centery - needleradius * math.sin(thetarad - math.pi / 2);      rightx = centerx - needleradius * math.cos(thetarad + math.pi / 2);     righty = centery - needleradius * math.sin(thetarad + math.pi / 2);      "m #{leftx} #{lefty} l #{topx} #{topy} l #{rightx} #{righty}"         var needle = svg.selectall( ".needle" )         .data( [0] )         .enter()          .append( 'line' )         .attr( "x1", 0 )         .attr( "x2", -130 )         .attr( "y1", 0 )         .attr( "y2", 0 )     .attr("width",500)     .attr("height",500)     // .attr("lowerlimit", 0)     // .attr("upperlimit", 10000)         .classed("needle", true)         .style( "stroke", "black" )         .attr( "transform", function( d ) {             return " translate(200,200) rotate(" + d + ")"         } );       console.log(svg.selectall( ".needle" ))         svg.selectall( ".needle" ).data( [(9000)/100] )             .transition()             .ease( d3.easeelasticout )             .duration( 2000 )             .attr( "transform", function( d ) {                 return "translate(200,200) rotate(" + d + ")"             });     }); // end of json func  // end of guage </script>   </body>  </html> 


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -