Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert all the example components, class to function components. #649

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 33 additions & 45 deletions example/src/App.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,38 @@
import React, { Component } from 'react'
import Area from './chart-types/Area'
import Bar from './chart-types/Bar'
import Column from './chart-types/Column'
import Line from './chart-types/Line'
import Donut from './chart-types/Donut'
import RadialBar from './chart-types/RadialBar'
import ChartUpdate from './ChartUpdate'
import React, { useState } from "react";
import Area from "./chart-types/Area";
import Bar from "./chart-types/Bar";
import Column from "./chart-types/Column";
import Line from "./chart-types/Line";
import Donut from "./chart-types/Donut";
import RadialBar from "./chart-types/RadialBar";
import ChartUpdate from "./ChartUpdate";

class App extends Component {
constructor (props) {
super(props)
export default function App() {
const [selectedChart, setSelectedChart] = useState("line");

this.changeChart = this.changeChart.bind(this)
const handleChartChange = (e) => {
setSelectedChart(e.target.value);
};

this.state = {
selectedChart: 'line'
}
}
return (
<div className="app">
<select id="lang" value={selectedChart} onChange={handleChartChange}>
<option value="line">Line</option>
<option value="area">Area</option>
<option value="bar">Bar</option>
<option value="column">Column</option>
<option value="radialbar">RadialBar</option>
<option value="donut">Donut</option>
<option value="updateExample">Chart Update Example</option>
</select>

changeChart (e) {
this.setState({selectedChart: e.target.value})
}

render () {
return (
<div className="app">
<select id="lang" value={this.state.selectedChart} onChange={this.changeChart}>
<option value="line" >Line</option>
<option value="area" >Area</option>
<option value="bar" >Bar</option>
<option value="column" >Column</option>
<option value="radialbar" >RadialBar</option>
<option value="donut" >Donut</option>
<option value="updateExample" >Chart Update Example</option>
</select>

{ this.state.selectedChart === 'area' ? (<Area></Area>) : null}
{ this.state.selectedChart === 'bar' ? (<Bar></Bar>) : null}
{ this.state.selectedChart === 'line' ? (<Line></Line>) : null}
{ this.state.selectedChart === 'column' ? (<Column></Column>) : null}
{ this.state.selectedChart === 'radialbar' ? (<RadialBar></RadialBar>) : null}
{ this.state.selectedChart === 'donut' ? (<Donut></Donut>) : null}
{ this.state.selectedChart === 'updateExample' ? (<ChartUpdate></ChartUpdate>) : null}
</div>
)
}
{selectedChart === "area" ? <Area></Area> : null}
{selectedChart === "bar" ? <Bar></Bar> : null}
{selectedChart === "line" ? <Line></Line> : null}
{selectedChart === "column" ? <Column></Column> : null}
{selectedChart === "radialbar" ? <RadialBar></RadialBar> : null}
{selectedChart === "donut" ? <Donut></Donut> : null}
{selectedChart === "updateExample" ? <ChartUpdate></ChartUpdate> : null}
</div>
);
}

export default App
Loading