Backend API
import React from 'react';
import RowTemplate from './RowTemplate.tsx';
const years = ['2021', '2022', '2023'];
function App() {
return (
<>
<div className="long-title"><h3>Monthly Prices of Oil, Gold and Silver</h3></div>
<div id="chart-demo">
<table className="demo-table">
<tbody>
<tr>
<th><div className="dx-screen-reader-only">Year</div></th>
<th>Oil (USD/barrel)</th>
<th>Gold (USD/troy ounce)</th>
<th>Silver (USD/troy ounce)</th>
</tr>
{
years.map((year, index) => <RowTemplate key={index} year={year} />)
}
</tbody>
</table>
</div>
</>
);
}
export default App;
import React from 'react';
import RowTemplate from './RowTemplate.js';
const years = ['2021', '2022', '2023'];
function App() {
return (
<>
<div className="long-title">
<h3>Monthly Prices of Oil, Gold and Silver</h3>
</div>
<div id="chart-demo">
<table className="demo-table">
<tbody>
<tr>
<th>
<div className="dx-screen-reader-only">Year</div>
</th>
<th>Oil (USD/barrel)</th>
<th>Gold (USD/troy ounce)</th>
<th>Silver (USD/troy ounce)</th>
</tr>
{years.map((year, index) => (
<RowTemplate
key={index}
year={year}
/>
))}
</tbody>
</table>
</div>
</>
);
}
export default App;
import React from 'react';
import Sparkline, {
Tooltip,
} from 'devextreme-react/sparkline';
import {
oilCosts,
silverCosts,
goldCosts,
} from './data.ts';
interface RowTemplateProps {
key: number;
year: string;
}
export default function RowTemplate(props: RowTemplateProps) {
return (
<tr>
<th>{props.year}</th>
<td>
<Sparkline
dataSource={oilCosts}
showMinMax={true}
className="sparkline"
argumentField="month"
valueField={props.year}
type="line"
>
<Tooltip format={{ type: 'currency', precision: 2 }} />
</Sparkline>
</td>
<td>
<Sparkline
dataSource={goldCosts}
lineWidth={3}
showMinMax={true}
showFirstLast={false}
className="sparkline"
argumentField="month"
valueField={props.year}
type="spline"
lineColor="#9ab57e"
minColor="#6babac"
maxColor="#ebdd8f"
>
<Tooltip format={{ type: 'currency', precision: 2 }} />
</Sparkline>
</td>
<td>
<Sparkline
dataSource={silverCosts}
pointSize={6}
className="sparkline"
argumentField="month"
valueField={props.year}
type="stepline"
lineColor="#e8c267"
firstLastColor="#e55253"
pointSymbol="square"
pointColor="#ebdd8f"
>
<Tooltip format={{ type: 'currency', precision: 2 }} />
</Sparkline>
</td>
</tr>
);
}
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.tsx';
ReactDOM.render(
<App />,
document.getElementById('app'),
);
export const oilCosts = [{
month: 1,
2021: 52.16,
2022: 89.16,
2023: 78.12,
}, {
month: 2,
2021: 61.55,
2022: 96.13,
2023: 76.83,
}, {
month: 3,
2021: 59.19,
2022: 100.53,
2023: 73.28,
}, {
month: 4,
2021: 63.50,
2022: 104.59,
2023: 79.45,
}, {
month: 5,
2021: 66.31,
2022: 114.38,
2023: 71.58,
}, {
month: 6,
2021: 73.52,
2022: 107.76,
2023: 70.25,
}, {
month: 7,
2021: 73.93,
2022: 101.31,
2023: 76.07,
}, {
month: 8,
2021: 68.43,
2022: 90.09,
2023: 81.39,
}, {
month: 9,
2021: 75.22,
2022: 79.91,
2023: 89.43,
}, {
month: 10,
2021: 83.50,
2022: 86.54,
2023: 85.64,
}, {
month: 11,
2021: 66.14,
2022: 80.48,
2023: 77.69,
}, {
month: 12,
2021: 75.33,
2022: 80.16,
2023: 71.90,
}];
export const goldCosts = [{
month: 1,
2021: 1866.98,
2022: 1816.51,
2023: 1894.75,
}, {
month: 2,
2021: 1808.17,
2022: 1856.30,
2023: 1858.74,
}, {
month: 3,
2021: 1718.23,
2022: 1947.83,
2023: 1912.12,
}, {
month: 4,
2021: 1760.27,
2022: 1933.88,
2023: 2000.13,
}, {
month: 5,
2021: 1850.26,
2022: 1848.33,
2023: 1992.05,
}, {
month: 6,
2021: 1834.57,
2022: 1836.57,
2023: 1942.92,
}, {
month: 7,
2021: 1807.84,
2022: 1738.41,
2023: 1951.01,
}, {
month: 8,
2021: 1784.28,
2022: 1764.56,
2023: 1918.41,
}, {
month: 9,
2021: 1777.27,
2022: 1680.78,
2023: 1915.65,
}, {
month: 10,
2021: 1776.85,
2022: 1664.15,
2023: 1916.14,
}, {
month: 11,
2021: 1820.23,
2022: 1725.06,
2023: 1984.45,
}, {
month: 12,
2021: 1790.43,
2022: 1796.87,
2023: 2027.01,
}];
export const silverCosts = [{
month: 1,
2021: 25.91,
2022: 23.13,
2023: 23.76,
}, {
month: 2,
2021: 27.35,
2022: 23.51,
2023: 21.90,
}, {
month: 3,
2021: 25.60,
2022: 25.17,
2023: 21.92,
}, {
month: 4,
2021: 25.63,
2022: 24.51,
2023: 24.98,
}, {
month: 5,
2021: 27.48,
2022: 21.90,
2023: 24.21,
}, {
month: 6,
2021: 26.98,
2022: 21.46,
2023: 23.34,
}, {
month: 7,
2021: 25.66,
2022: 19.07,
2023: 24.08,
}, {
month: 8,
2021: 24.01,
2022: 19.74,
2023: 23.55,
}, {
month: 9,
2021: 23.19,
2022: 18.91,
2023: 23.15,
}, {
month: 10,
2021: 23.36,
2022: 19.34,
2023: 22.25,
}, {
month: 11,
2021: 24.16,
2022: 21.03,
2023: 23.47,
}, {
month: 12,
2021: 22.47,
2022: 23.29,
2023: 24.03,
}];
import React from 'react';
import Sparkline, { Tooltip } from 'devextreme-react/sparkline';
import { oilCosts, silverCosts, goldCosts } from './data.js';
export default function RowTemplate(props) {
return (
<tr>
<th>{props.year}</th>
<td>
<Sparkline
dataSource={oilCosts}
showMinMax={true}
className="sparkline"
argumentField="month"
valueField={props.year}
type="line"
>
<Tooltip format={{ type: 'currency', precision: 2 }} />
</Sparkline>
</td>
<td>
<Sparkline
dataSource={goldCosts}
lineWidth={3}
showMinMax={true}
showFirstLast={false}
className="sparkline"
argumentField="month"
valueField={props.year}
type="spline"
lineColor="#9ab57e"
minColor="#6babac"
maxColor="#ebdd8f"
>
<Tooltip format={{ type: 'currency', precision: 2 }} />
</Sparkline>
</td>
<td>
<Sparkline
dataSource={silverCosts}
pointSize={6}
className="sparkline"
argumentField="month"
valueField={props.year}
type="stepline"
lineColor="#e8c267"
firstLastColor="#e55253"
pointSymbol="square"
pointColor="#ebdd8f"
>
<Tooltip format={{ type: 'currency', precision: 2 }} />
</Sparkline>
</td>
</tr>
);
}
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.js';
ReactDOM.render(<App />, document.getElementById('app'));
export const oilCosts = [
{
month: 1,
2021: 52.16,
2022: 89.16,
2023: 78.12,
},
{
month: 2,
2021: 61.55,
2022: 96.13,
2023: 76.83,
},
{
month: 3,
2021: 59.19,
2022: 100.53,
2023: 73.28,
},
{
month: 4,
2021: 63.5,
2022: 104.59,
2023: 79.45,
},
{
month: 5,
2021: 66.31,
2022: 114.38,
2023: 71.58,
},
{
month: 6,
2021: 73.52,
2022: 107.76,
2023: 70.25,
},
{
month: 7,
2021: 73.93,
2022: 101.31,
2023: 76.07,
},
{
month: 8,
2021: 68.43,
2022: 90.09,
2023: 81.39,
},
{
month: 9,
2021: 75.22,
2022: 79.91,
2023: 89.43,
},
{
month: 10,
2021: 83.5,
2022: 86.54,
2023: 85.64,
},
{
month: 11,
2021: 66.14,
2022: 80.48,
2023: 77.69,
},
{
month: 12,
2021: 75.33,
2022: 80.16,
2023: 71.9,
},
];
export const goldCosts = [
{
month: 1,
2021: 1866.98,
2022: 1816.51,
2023: 1894.75,
},
{
month: 2,
2021: 1808.17,
2022: 1856.3,
2023: 1858.74,
},
{
month: 3,
2021: 1718.23,
2022: 1947.83,
2023: 1912.12,
},
{
month: 4,
2021: 1760.27,
2022: 1933.88,
2023: 2000.13,
},
{
month: 5,
2021: 1850.26,
2022: 1848.33,
2023: 1992.05,
},
{
month: 6,
2021: 1834.57,
2022: 1836.57,
2023: 1942.92,
},
{
month: 7,
2021: 1807.84,
2022: 1738.41,
2023: 1951.01,
},
{
month: 8,
2021: 1784.28,
2022: 1764.56,
2023: 1918.41,
},
{
month: 9,
2021: 1777.27,
2022: 1680.78,
2023: 1915.65,
},
{
month: 10,
2021: 1776.85,
2022: 1664.15,
2023: 1916.14,
},
{
month: 11,
2021: 1820.23,
2022: 1725.06,
2023: 1984.45,
},
{
month: 12,
2021: 1790.43,
2022: 1796.87,
2023: 2027.01,
},
];
export const silverCosts = [
{
month: 1,
2021: 25.91,
2022: 23.13,
2023: 23.76,
},
{
month: 2,
2021: 27.35,
2022: 23.51,
2023: 21.9,
},
{
month: 3,
2021: 25.6,
2022: 25.17,
2023: 21.92,
},
{
month: 4,
2021: 25.63,
2022: 24.51,
2023: 24.98,
},
{
month: 5,
2021: 27.48,
2022: 21.9,
2023: 24.21,
},
{
month: 6,
2021: 26.98,
2022: 21.46,
2023: 23.34,
},
{
month: 7,
2021: 25.66,
2022: 19.07,
2023: 24.08,
},
{
month: 8,
2021: 24.01,
2022: 19.74,
2023: 23.55,
},
{
month: 9,
2021: 23.19,
2022: 18.91,
2023: 23.15,
},
{
month: 10,
2021: 23.36,
2022: 19.34,
2023: 22.25,
},
{
month: 11,
2021: 24.16,
2022: 21.03,
2023: 23.47,
},
{
month: 12,
2021: 22.47,
2022: 23.29,
2023: 24.03,
},
];
<!DOCTYPE html>
<html lang="en">
<head>
<title>DevExtreme Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" />
<link rel="stylesheet" type="text/css" href="./bundle.css" />
</head>
<body class="dx-viewport">
<div class="demo-container">
<div id="app"></div>
</div>
<script src="bundles/vendor/react.vendor.js"></script>
<script src="./bundle.js"></script>
</body>
</html>
#chart-demo {
height: 440px;
}
.demo-table {
width: 100%;
border: 1px solid #c2c2c2;
border-collapse: collapse;
}
.demo-table th,
.demo-table td {
font-weight: 400;
width: 200px;
padding: 25px 10px 5px;
border: 1px solid #c2c2c2;
}
.demo-table th {
padding: 25px 15px 20px;
border: 1px solid #c2c2c2;
}
.demo-table tr:nth-child(2) td {
border-top: 1px solid #c2c2c2;
}
.demo-table td:first-of-type {
border-left: 1px solid #c2c2c2;
}
.demo-table .sparkline {
width: 200px;
height: 30px;
}
.long-title h3 {
font-weight: 200;
font-size: 28px;
text-align: center;
margin-bottom: 20px;
margin-top: 0;
}