How to create Histogram with grouped data in Victory (ReactJS)?

Viewed 209

I'm trying to create a histogram with Value, Id and Group code. I need to group the Ids based on the group code and put the labels on top. I'm also trying to add a horizontal scroll bar. Can you help me with this?

I tried to do like in this picture but I couldn't. nodesc

My data is in the form of this object

{
        id: 1,
        value: 0.16882,
        group_id: 'group_1',
        fill: 'red',
}
const App = () => {
    const sharedAxisStyles = {
        tickLabels: {
            fontSize: 10
        },
        axisLabel: {
            padding: 39,
            fontSize: 12,
        },
        grid: {
            stroke: "#546E7A",
            strokeWidth: 0.1,
        }
    };

    return (
        <VictoryChart
            domainPadding={{
                x: 20,
            }}
            containerComponent={(
                <VictoryZoomContainer
                    allowZoom={false}
                    zoomDomain={{
                        x: [0, 22],
                    }}
                />
            )}
        >
            <VictoryLabel
                x={225}
                y={30}
                textAnchor="middle"
                text="Group code"
            />
            <VictoryBar
                data={data}
                x={(x) => `id_${x.id}`}
                y="value"
                barWidth={15.8}
                style={{
                    data: {
                        fill: ({datum}) => datum.fill,
                    }
                }}
            />
            <VictoryAxis
                tickCount={22}
                tickLabelComponent={<VictoryLabel
                    angle={-90}
                    textAnchor="end"
                    style={[
                        { fontSize: 3, fontWeight: 'bold', fill: '#78909C' },
                    ]}
                />}
            />

            <VictoryAxis
                dependentAxis
                label="Value"
                tickFormat={(t) => {
                    return (
                        (t).toFixed(2)
                    );
                }}
                style={sharedAxisStyles}
            />

        </VictoryChart>
    );
};

When I write these codes, the output I get is like this:

nodesc

1 Answers
Related