I am having UX issues with overlapping Bars on BarChart with certain datasets. Example attached is the code
https://codesandbox.io/p/sandbox/javascript-column-chart-forked-p59p75?file=%2Fsrc%2FApp.tsx%3A49%2C1
please uncomment lines at 47 and 48 for a different set of x and y values where it works fine.
Not sure what am i doing wrong.
- vamsi pallem asked 2 months ago
-
Any update on this issue ?
- You must login to post comments
Hi
You get this problem if you have bar charts with sparse data (ie not enough columns to fill the x axis). By default, SciChart calculates the column width by dividing the total axis length by the number of columns.
You can either adjust the dataPointWidth, or if you need things a bit more dynamic, you can override getDataPointWidth as shown below. Here I am calculating the width based on the gap between the first 2 points.
// Create an add a column series
const colSeries = new FastColumnRenderableSeries(wasmContext, {
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues }),
// Fill & stroke support Hex strings and rgba()
fill: appTheme.PaleSkyBlue + "77",
dataPointWidth: 0.8,
});
xValues.sort();
colSeries.getDataPointWidth = (xCoordCalc, widthFraction) => {
//return 25;
const pointGap =
xCoordCalc.getCoordinate(xValues[1]) -
xCoordCalc.getCoordinate(xValues[0]);
console.log(pointGap, widthFraction);
return pointGap * widthFraction;
};
sciChartSurface.renderableSeries.add(colSeries);
Regards
David
- David Burleigh answered 2 months ago
- You must login to post comments
I have tried the dynamic way by overriding getDataPointWidth and it did fix the problem where the data points were sparse but broke (showing overlapping bars) for other scenarios where it used to work before the fix.
- vamsi pallem answered 2 months ago
- last edited 2 months ago
- You must login to post comments
Please login first to submit.