App.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React from 'react';
  2. import logo from './logo.svg';
  3. import './App.css';
  4. import BarChart from 'chart-race-react';
  5. //const data = {"apple": "2", "ELENA": "5", "orange": "2", "yoghurt": "3", "pinguin": "1", "blub": "5"}
  6. const data = ['apple', 'banana', 'orange', 'yoghurt', 'pinguin', 'blub'].reduce((res, item) => ({...res, ...{[item]: Array(20).fill(0).map(_ => Math.floor(20 * Math.random()))}}), {});
  7. const randomColor = () => {
  8. return `rgb(${255 * Math.random()}, ${255 * Math.random()}, ${255})`;
  9. }
  10. const len = data[Object.keys(data)[0]].length;
  11. const keys = Object.keys(data);
  12. const colors = keys.reduce((res, item) => ({
  13. ...res,
  14. ...{ [item]: randomColor() }
  15. }), {});
  16. const labels = keys.reduce((res, item, idx) => {
  17. return{
  18. ...res,
  19. ...{[item]: (
  20. <div style={{textAlign:"center",}}>
  21. <div>{item}</div>
  22. </div>
  23. )}
  24. }}, {});
  25. const time = Array(20).fill(0).map((itm, idx) => idx + 1);
  26. function App() {
  27. return (
  28. <div className="App">
  29. <header className="App-header">
  30. <img src={logo} className="App-logo" alt="logo" />
  31. <p>
  32. Edit <code>src/App.js</code> and save to reload.
  33. </p>
  34. <a
  35. className="App-link"
  36. href="https://reactjs.org"
  37. target="_blank"
  38. rel="noopener noreferrer"
  39. >
  40. Learn React
  41. </a>
  42. </header>
  43. <h1>Test</h1>
  44. <div style={{width: "500px"}}>
  45. <BarChart
  46. start={true}
  47. data={data}
  48. timeline={time}
  49. labels={labels}
  50. colors={colors}
  51. len={len}
  52. timeout={400}
  53. delay={1000}
  54. timelineStyle={{
  55. textAlign: "center",
  56. fontSize: "50px",
  57. color: "rgb(148, 148, 148)",
  58. marginBottom: "100px"
  59. }}
  60. textBoxStyle={{
  61. textAlign: "right",
  62. color: "rgb(133, 131, 131)",
  63. fontSize: "30px",
  64. }}
  65. barStyle={{
  66. height: "60px",
  67. marginTop: "10px",
  68. borderRadius: "10px",
  69. }}
  70. width={[15, 75, 10]}
  71. maxItems={5}
  72. />
  73. </div>
  74. <h1>Test</h1>
  75. </div>
  76. );
  77. }
  78. export default App;