removed adv chart

This commit is contained in:
2024-03-03 22:57:13 -05:00
parent 1bd646805c
commit c9dde12f83
4 changed files with 90 additions and 220 deletions
+70
View File
@@ -0,0 +1,70 @@
"use client";
import { createChart, ColorType } from "lightweight-charts";
import React, { MutableRefObject, useEffect, useRef } from "react";
import { indexData, portfolioData } from "@/app/MockData/MockData";
const Chart = (props: any) => {
const {
data,
colors: {
backgroundColor = "transparent",
portfolioLineColor = "#FACC15",
indexLineColor = "#FFFFFF",
textColor = "white",
} = {},
} = props;
const chartContainerRef = useRef() as MutableRefObject<HTMLDivElement>;
useEffect(() => {
const handleResize = () => {
chart.applyOptions({
width: chartContainerRef.current.clientWidth * 0.95,
});
};
const chart = createChart(chartContainerRef.current, {
layout: {
background: { type: ColorType.Solid, color: backgroundColor },
textColor,
},
width: chartContainerRef.current.clientWidth * 0.95,
height: chartContainerRef.current.clientHeight * 0.95,
grid: {
vertLines: {
visible: false,
},
},
});
chart.timeScale().fitContent();
const portfolioSeries = chart.addLineSeries({
color: portfolioLineColor,
});
portfolioSeries.setData(portfolioData);
const indexSeries = chart.addLineSeries({
color: indexLineColor,
});
indexSeries.setData(indexData);
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
chart.remove();
};
}, [data, backgroundColor, portfolioLineColor, indexLineColor, textColor]);
return (
<div
className="flex justify-center h-full"
ref={chartContainerRef}
id="chart"
/>
);
};
export default Chart;