Pre loader

Overlapping Bar Chart

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered
0
0

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.

Version
3.3.560
  • You must to post comments
Best Answer
0
0

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

  • You must to post comments
0
0

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.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.