What's the best way to graph datasets with different labels? #12078
Unanswered
AjaniBilby
asked this question in
Q&A
Replies: 1 comment
-
Also FYI, the reason that chart setup looks a little weird is that's the server side render of the content, which gets JSONified and remounted on the client like this: export function Chart(props: {
type: ChartConfiguration["type"],
data: ChartConfiguration["data"] & { datasets: Array<TrendLine>},
options: ChartConfiguration["options"],
style?: CSSProperties
hideZeros?: boolean
}) {
const chartRef = useRef <HTMLCanvasElement> (null);
const chartInstanceRef = useRef<ChartJS | null>(null);
useEffect(() => {
if (!chartRef.current) return;
const ctx = chartRef.current.getContext("2d");
if (!ctx) return;
// Destroy existing chart instance
if (chartInstanceRef.current) chartInstanceRef.current.destroy();
if (props.hideZeros) {
props.options ||= {};
props.options.plugins ||= {};
props.options.plugins.tooltip ||= {};
props.options.plugins.tooltip.filter = function(tooltipItem) {
return tooltipItem.parsed.x !== null && tooltipItem.parsed.x !== 0;
}
props.options.plugins.tooltip.callbacks ||= {};
props.options.plugins.tooltip.callbacks.title = function(tooltipItems) {
if (tooltipItems.length === 0) return '';
return tooltipItems[0].label;
}
}
// Create new chart instance
chartInstanceRef.current = new ChartJS(ctx, {
type: props.type,
data: props.data,
options: props.options,
});
return () => {
if (!chartInstanceRef.current) return;
chartInstanceRef.current.destroy();
chartInstanceRef.current = null;
};
}, []);
return <div style={{ display: "block" }}>
<canvas ref={chartRef} style={props.style}></canvas>
</div>;
} Also the usage of this table in production has 86 different labels at the moment, it's basically a breakdown of the time costs of each level that can make up a repair. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to graph a horizontal bar chart, where I want the different "groups" to be colour coded, and you can click on the legend to hide a group. However every option I can find to get something like this working has a lot of painful side affects.
This is the best I've come up with so far

Option 1 is the closest I can get visually to what I want, but there are clearly four bars on each label with the other three all being zero causing weird spacing, and even weirder hovering behaviour.
Also unfortunately the labels of different groups don't disappear when I hide the group, but I presume that's just something I'm going to have to live with.

All I really want to make this passable is to get rid of the
0
value bars on a label.Not sure if it's possible, but if anyone has any suggestions they would be much appreciated
Beta Was this translation helpful? Give feedback.
All reactions