0

I have BarChart but I don't know how to count similar data in barChart. I have no idea how to do this. I have tried several ways, but I'm not getting a working solution.

My main component where I use axios and BarChart

let tableCash = "CLDR display name";
let conutrCode = "Country Code";
let countryName = "Country Name";
let currencyName = "ISO4217-currency_name";
let currencyMinor = "ISO4217-currency_minor_unit";
let year = "Year";

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {      
      year: [],
      minor: []      
    }
  }

  counter = (e) => {
    var  count = {};
    this.state.minor.forEach(function(i) { count[i] = (count[i]||0) + 1;});
    console.log(count);
  }
  componentDidMount() {
    axios.get('https://pkgstore.datahub.io/core/population/population_json/data/43d34c2353cbd16a0aa8cadfb193af05/population_json.json')
      .then(res => {
        console.log(res.data.slice(11449, 11505));
        this.setState({
          year: res.data,
        })
      })
      axios.get('https://pkgstore.datahub.io/core/country-codes/country-codes_json/data/471a2e653140ecdd7243cdcacfd66608/country-codes_json.json')
      .then(res => {
        // console.log(res.data.map(eee => eee.Capital));
        console.log(res.data.map(eee => eee[currencyMinor]));
        this.setState({
          minor: res.data,
        })
      })
      // this.counter();
    }
  render() {
    const { year, minor } = this.state;    
    const dataList = year.length ? (year.slice(11449, 11506).filter((album, i) => {
      return (
        <ul>
          {album.Year}
          {album.Value}
        </ul>
      );
    }).map(ee => ee)
    ) : (
        <div className="center">No data yet! </div>
    )
    const dataList2 = minor.length ? (minor.filter((album, i) => {
      return (
        <ul>
          {album.currencyMinor}
          {album.currencyName}
        </ul>
      );
    }).map(ee => ee)
    ) : (
        <div className="center">No data yet! </div>
    )
    return (
      <div className="containerLoader" style={containerLoader}>
        <div className="card z-depth-0 project-summary thumb">
          <div className="card-content grey-text text-darken-3 containerPost">
            <DataThumb data={dataList} />
            {/* {this.counter()} */}
            <BarCharts  data={dataList2} />
          </div>          
        </div>
      </div>
    )
  }
}

This is an empty component where I'm sending the data.


function DataThumb(props) {
  return (
    <LineChart width={900} height={250} data={props.data}
      margin={{ top: 5, right: 30, left: 50, bottom: 5 }}>
      <CartesianGrid strokeDasharray="3 3" />
      <XAxis label={{ value: 'Years', position: 'insideBottomRight', offset: -10 }} dataKey="Year" />
      <YAxis label={{ value: 'Population', angle: -90, position: 'insideLeft', offset: -20 }} />
      <Tooltip />
      <Legend />
      <Line type="monotone" dataKey="Value" stroke="#8884d8" />
    </LineChart>
  )
}

function BarCharts(props) {
  return (
    <BarChart width={730} height={250} data={props.data}>
      <CartesianGrid strokeDasharray="3 3" />
      <XAxis dataKey="ISO4217-currency_name" />
      <YAxis />
      <Tooltip />
      <Legend />
      {/* <Bar dataKey="ISO4217-currency_name" fill="#8884d8" /> */}
      <Bar dataKey="ISO4217-currency_minor_unit" fill="#82ca9d" />
    </BarChart>
  )
}

const containerLoader = {
  display: 'flex',
  justifyContent: 'center',
}

I don't have any idea how to count this same data. If somebody has an idea please help! :-)

Edit 1:

enter image description here

SeN
  • 151
  • 1
  • 2
  • 11
  • What do you mean by counting the same data? what is your data structure and what factor indicates the similarity? send in a sample of the data that you receive – Amir-Mousavi May 16 '19 at 16:27
  • see edit 1 at the top – SeN May 16 '19 at 16:33
  • In this link you can see data in console and result https://scherlock90.github.io/task-charts/ – SeN May 16 '19 at 16:35
  • so the `minor` in the sate contains that array (250 ), and you want to count how many 0s, how many 1s ... are existing in that array? – Amir-Mousavi May 16 '19 at 16:42
  • if it is so, your question is not related to React, you can delete all those JSX component codes and find the [answer here](https://stackoverflow.com/a/17313444/1624844) – Amir-Mousavi May 16 '19 at 16:46
  • yes, I want to count it and then display it on BarChart – SeN May 16 '19 at 16:47

0 Answers0