javascript - Convert string to integer in reactjs - Stack Overflow

if(this.state.chartCategory == 'D3Chart'){console.log("chartdata for d3 charts", th

if(this.state.chartCategory == 'D3Chart'){
      console.log("chartdata for d3 charts", this.state.d3line.chartData);

        switch(this.state.chartType){
          case 'area': return <div  style={{width: 900, height:300}}><Areagraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          case 'pie': return  <div style={{width: 900, height:500}}><Piegraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          case 'bar': return  <div  style={{width: 900, height:300}}><Bargraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          /*case 'column': return  <div className = "graphContainer" style={{width: 900, height:300, overflow: "hidden", resize: "both", paddingBottom: "10px", border: "1px solid black"}}><Columngraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;*/
          case 'line' : return <div  style={{width: 900, height:300}}><Linegraph  data = {this.state.d3line.chartData} vars = {{x:this.state.d3line.x, y: this.state.d3line.y, group: this.state.d3line.x}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          default: return null;
       }   

    }

In the console I am printing the data which i want to convert from string to integerIf number, convert string to integer, number also taking as string, How to convert into number need to remove " "

If you check in the picture I need to convert, if it a number alone

if(this.state.chartCategory == 'D3Chart'){
      console.log("chartdata for d3 charts", this.state.d3line.chartData);

        switch(this.state.chartType){
          case 'area': return <div  style={{width: 900, height:300}}><Areagraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          case 'pie': return  <div style={{width: 900, height:500}}><Piegraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          case 'bar': return  <div  style={{width: 900, height:300}}><Bargraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          /*case 'column': return  <div className = "graphContainer" style={{width: 900, height:300, overflow: "hidden", resize: "both", paddingBottom: "10px", border: "1px solid black"}}><Columngraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;*/
          case 'line' : return <div  style={{width: 900, height:300}}><Linegraph  data = {this.state.d3line.chartData} vars = {{x:this.state.d3line.x, y: this.state.d3line.y, group: this.state.d3line.x}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          default: return null;
       }   

    }

In the console I am printing the data which i want to convert from string to integerIf number, convert string to integer, number also taking as string, How to convert into number need to remove " "

If you check in the picture I need to convert, if it a number alone

Share Improve this question edited Nov 24, 2017 at 9:17 siva asked Nov 24, 2017 at 8:40 sivasiva 451 gold badge4 silver badges12 bronze badges 3
  • have a look here – ztadic91 Commented Nov 24, 2017 at 8:48
  • 3 Possible duplicate of How do I convert a string into an integer in JavaScript? – ztadic91 Commented Nov 24, 2017 at 8:49
  • Possible duplicate of How to convert string to integer from json response in reactjs – Timothy Groote Commented Nov 24, 2017 at 10:35
Add a ment  | 

1 Answer 1

Reset to default 1

I'm not really sure if this really is different using ReactJs, but did you try to parseInt() the strings?

I'm not really understanding what you are trying to do, but the most simple way for type-conversion would be the native functions of Javascript!?

https://www.w3schools./jsref/jsref_parseint.asp

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745252612a4618768.html

相关推荐

  • javascript - Convert string to integer in reactjs - Stack Overflow

    if(this.state.chartCategory == 'D3Chart'){console.log("chartdata for d3 charts", th

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信