charting update

This commit is contained in:
2024-03-04 13:22:19 -05:00
parent c9dde12f83
commit 8beafc01db
2 changed files with 41 additions and 24 deletions
+33 -19
View File
@@ -4,16 +4,30 @@ 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;
interface ChartProps {
series: Series[];
colors: {
backgroundColor: string;
textColor: string;
};
config?: object;
}
interface Series {
data: typeof portfolioData;
seriesColor: string;
}
const Chart = ({ series, colors, config }: ChartProps) => {
// const {
// data,
// colors: {
// backgroundColor = "transparent",
// portfolioLineColor = "#FACC15",
// indexLineColor = "#FFFFFF",
// textColor = "white",
// } = {},
// } = props;
const chartContainerRef = useRef() as MutableRefObject<HTMLDivElement>;
@@ -26,8 +40,8 @@ const Chart = (props: any) => {
const chart = createChart(chartContainerRef.current, {
layout: {
background: { type: ColorType.Solid, color: backgroundColor },
textColor,
background: { type: ColorType.Solid, color: colors.backgroundColor },
textColor: colors.textColor,
},
width: chartContainerRef.current.clientWidth * 0.95,
height: chartContainerRef.current.clientHeight * 0.95,
@@ -40,14 +54,14 @@ const Chart = (props: any) => {
chart.timeScale().fitContent();
const portfolioSeries = chart.addLineSeries({
color: portfolioLineColor,
color: series[0].seriesColor,
});
portfolioSeries.setData(portfolioData);
portfolioSeries.setData(series[0].data);
const indexSeries = chart.addLineSeries({
color: indexLineColor,
});
indexSeries.setData(indexData);
// const indexSeries = chart.addLineSeries({
// color: indexLineColor,
// });
// indexSeries.setData(indexData);
window.addEventListener("resize", handleResize);
@@ -56,7 +70,7 @@ const Chart = (props: any) => {
chart.remove();
};
}, [data, backgroundColor, portfolioLineColor, indexLineColor, textColor]);
});
return (
<div