Pierre-Alexandre Montiel
08/19/2024, 7:43 PMimport React from "react";
import { selectColorPalette, useDashboardSelector, useInsightWidgetDataView } from "@gooddata/sdk-ui-dashboard";
import { IInsightWidget } from "@gooddata/sdk-model";
import { IErrorProps, ILoadingProps } from "@gooddata/sdk-ui";
import { CartesianGrid, LabelList, Line, LineChart, XAxis } from "recharts";
// import { ChartTooltip, ChartTooltipContent } from "@/components/ui/chart";
interface ILineChartProps {
widget: IInsightWidget;
ErrorComponent: React.ComponentType<IErrorProps>;
LoadingComponent: React.ComponentType<ILoadingProps>;
}
export const LineChartWidget: React.FC<ILineChartProps> = ({ _widget_, _LoadingComponent_, _ErrorComponent_ }) => {
// const colorPalette = useDashboardSelector(selectColorPalette).map(
// (color) => rgba(${color.fill.r}, ${color.fill.g}, ${color.fill.b}, .5)
// );
const { result, error, status } = useInsightWidgetDataView({
insightWidget: widget,
});
if (status === "loading" || status === "pending") {
return <LoadingComponent />;
}
if (status === "error" || !result) {
return <ErrorComponent _message_={error?.message ?? "Unknown error"} />;
}
if (result) {
// console.log("Insight Data 1:", result);
// console.log("Insight Data 2:", result.data());
// console.log("Insight Data 3:", result.data().slices());
console.log("Insight Data 4:", result.data().slices().toArray());
} else {
console.error("No result data available.");
}
const data = result
.data()
.slices()
.toArray()
.map((_slice_) => ({
month: slice.sliceTitles()[0], // Get the slice title
value: slice.rawData()[0], // Extract the value from the rawData method
// color: colorPalette[i % colorPalette.length], // Assign a color from the palette
}));
return (
<LineChart
_data_={data}
_margin_={{
top: 20,
left: 12,
right: 12,
}}
>
<CartesianGrid _vertical_={false} />
<XAxis
_dataKey_="month"
_tickLine_={false}
_axisLine_={false}
_tickMargin_={8}
_tickFormatter_={(_value_) => value.slice(0, 3)}
/>
{/* <ChartTooltip cursor={false} content={<ChartTooltipContent indicator="line" />} /> */}
<Line
_dataKey_="value"
_type_="natural"
_stroke_="var(--color-desktop)"
_strokeWidth_={2}
_dot_={{
fill: "var(--color-desktop)",
}}
_activeDot_={{
r: 6,
}}
>
<LabelList _position_="top" _offset_={12} _className_="fill-foreground" _fontSize_={12} />
</Line>
</LineChart>
);
};Radek Novacek
08/20/2024, 12:24 PMpackage.json
is probably the best for this 🙂 Also, have you been following any guides when it comes to the plugin itself? There's a pretty good one on the GD GitHub here in case you want to double-check your steps!Pierre-Alexandre Montiel
08/20/2024, 1:00 PMRadek Novacek
08/20/2024, 1:43 PM.env.secrets
and running npm run
), and did that work?Pierre-Alexandre Montiel
08/20/2024, 1:44 PMRadek Novacek
08/20/2024, 1:58 PMRadek Novacek
08/20/2024, 2:00 PMPierre-Alexandre Montiel
08/20/2024, 2:01 PMRadek Novacek
08/20/2024, 2:25 PMconsole.log
fires, and I'm assuming the Activities Growth by Year title is coming from the LineChartWrapper
, but the actual chart itself is blank.. I'm wondering if this might mean the problem isn't in the plugin setup but somewhere in the Recharts part.
If you try to skip the Recharts bit and just render like a testing phrase or something (still using the wrapper, but replacing the Recharts in LineChartWidget
), do we get the same result or does that work? It'd be helpful to try and isolate the root of the issue 🙂Pierre-Alexandre Montiel
08/20/2024, 2:30 PMRadek Novacek
08/20/2024, 2:35 PMPierre-Alexandre Montiel
08/20/2024, 3:15 PM