siva
siva

Reputation: 45

Convert string to integer in reactjs

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

Upvotes: 0

Views: 15190

Answers (1)

bquarta
bquarta

Reputation: 569

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.com/jsref/jsref_parseint.asp

Upvotes: 1

Related Questions