asb_cloud_front/src/components/charts/ChartTime.js

79 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-04-09 17:59:35 +05:00
import React, { useEffect, useRef} from 'react';
2021-04-11 15:29:53 +05:00
import { Chart, TimeScale, LinearScale, Legend, LineController, PointElement, LineElement } from 'chart.js'
//import Chart from 'chart.js/auto';
2021-04-11 12:55:15 +05:00
import 'chartjs-adapter-date-fns';
2021-04-11 15:29:53 +05:00
Chart.register( TimeScale, LinearScale, LineController, LineElement, PointElement, Legend );
2021-04-09 17:59:35 +05:00
const options = {
//showLine :true,
2021-04-11 15:29:53 +05:00
//indexAxis:'y',
2021-04-09 17:59:35 +05:00
//maintainAspectRatio: false,
//responsive:false,
scales: {
y:{
type: 'time',
time: {
unit: 'second',
displayFormats: {
millisecond: 'HH:mm:ss.SSS',
second: 'HH:mm:ss',
minute: 'HH:mm:ss',
hour: 'dd HH:mm:ss',
day: 'MM.dd HH:mm',
week: 'yy.MM.dd HH:mm',
month: 'yyyy.MM.dd',
quarter: 'yyyy.MM.dd',
year: 'yyyy.MM',
},
},
},
2021-04-11 12:55:15 +05:00
x:{
type:'linear'
}
2021-04-09 17:59:35 +05:00
},
}
const data= {
datasets: [{
label: 'Torque',
data: [
{x: 10, y: '2021-04-09T17:50:34.021679+05:00'},
{x: 15, y: '2021-04-09T17:50:33.021679+05:00'},
{x: 20, y: '2021-04-09T17:50:32.021679+05:00'}],
2021-04-11 12:55:15 +05:00
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
2021-04-09 17:59:35 +05:00
},
{
label: 'Pressure',
data: [
{x: 11, y: '2021-04-09T17:50:34.021679+05:00'},
{x: 14, y: '2021-04-09T17:50:33.021679+05:00'},
{x: 21, y: '2021-04-09T17:50:32.021679+05:00'}],
2021-04-11 12:55:15 +05:00
borderColor: 'rgba(0, 99, 132, 0.5)',
2021-04-09 17:59:35 +05:00
}
]
}
2021-04-11 15:29:53 +05:00
// export type LineConfig = {
// login?: string | null;
// password?: string | null;
// }
export function ChartTime(/*props*/){
2021-04-09 17:59:35 +05:00
const chartRef = useRef(null)
useEffect(()=>{
let chart = new Chart(chartRef.current, {
type: 'line',
data,
options})
//chart.canvas.parentNode.style.height = '128px';
2021-04-11 15:29:53 +05:00
return () => chart.destroy()
2021-04-09 17:59:35 +05:00
},[])
return(<canvas ref={chartRef} />)
}