-
-
Save Anshad786/1bdff51695adcf37cb4c9bef83d19d66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState, useEffect } from 'react'; | |
| import { Line } from 'react-chartjs-2'; | |
| import axios from 'axios'; | |
| function App() { | |
| const [chartData, setChartData] = useState({}); | |
| useEffect(() => { | |
| const fetchData = async () => { | |
| const result = await axios.get('http://localhost:5000/stock/AAPL'); | |
| const raw = result.data['Time Series (5min)']; | |
| const labels = Object.keys(raw).reverse(); | |
| const data = labels.map(time => raw[time]['4. close']); | |
| setChartData({ | |
| labels, | |
| datasets: [ | |
| { | |
| label: 'Apple Stock Price', | |
| data, | |
| fill: false, | |
| borderColor: 'blue', | |
| }, | |
| ], | |
| }); | |
| }; | |
| fetchData(); | |
| }, []); | |
| return ( | |
| <div> | |
| <h1>Stock Chart</h1> | |
| <Line data={chartData} /> | |
| </div> | |
| ); | |
| } | |
| export default App; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import logo from '../logo.svg'; | |
| class About extends Component { | |
| render() { | |
| return ( | |
| <div className="App"> | |
| <header className="App-header"> | |
| <img src={logo} className="App-logo" alt="logo" /> | |
| <h1 className="App-title">About Page</h1> | |
| </header> | |
| <p className="App-intro"> | |
| Welcome to the about page :) | |
| </p> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default About; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import logo from '../logo.svg'; | |
| class Home extends Component { | |
| render() { | |
| return ( | |
| <div className="App"> | |
| <header className="App-header"> | |
| <img src={logo} className="App-logo" alt="logo" /> | |
| <h1 className="App-title">Home Page</h1> | |
| </header> | |
| <p className="App-intro"> | |
| Welcome to the home page :) | |
| </p> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default Home; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Home from '../components/Home'; | |
| import About from '../components/About'; | |
| export const Routes = [ | |
| { | |
| path: '/', | |
| exact: true, | |
| component: Home | |
| }, | |
| { | |
| path: '/about-us', | |
| exact: false, | |
| component: About | |
| }, | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import './index.css'; | |
| import App from './App'; | |
| import registerServiceWorker from './registerServiceWorker'; | |
| import { BrowserRouter } from 'react-router-dom'; | |
| ReactDOM.render(<BrowserRouter><App /></BrowserRouter>, document.getElementById('root')); | |
| registerServiceWorker(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment