Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syncfusion_flutter_charts Stacked bar series bug - not stacked properly #2155

Open
Justus-M opened this issue Nov 3, 2024 · 1 comment
Open
Labels
charts Charts component waiting for customer response Cannot make further progress until the customer responds.

Comments

@Justus-M
Copy link

Justus-M commented Nov 3, 2024

Bug description

Stacked bar series with categorical x axis shows bars overlapping and with space between them

Screenshot 2024-11-03 at 16 39 45

Steps to reproduce

  1. Create a bar graph with a categorical x column

Code sample

Code sample
  var request = ref.watch(queryRequestProvider(query.id));
    var result = request.getFilteredResult(query.sliders, query)!;
    result = result.map((key, value) => MapEntry(
        key,
        value.firstOrNull is String &&
                !value.any((v) => num.tryParse(v.toString()) == null)
            ? value.map((e) => num.parse(e.toString())).toList()
            : value));

    var xAxis = result[query.xAxisVariable]
            ?.firstWhere((element) => element != null) is DateTime
        ? DateTimeAxis(
            title: AxisTitle(
                text: query.xAxisName ??
                    query.xAxisVariable?.replaceAll('_', ' ')))
        : CategoryAxis(
            maximumLabelWidth: 240,
            labelIntersectAction: AxisLabelIntersectAction.rotate45,
            title: AxisTitle(
                text: query.xAxisName ??
                    query.xAxisVariable?.replaceAll('_', ' ') ??
                    query.yAxisVariable.keys.firstOrNull));
    var dataSeries =
        ref.watch(queryRequestProvider(query.id)).getDataSeries(query, result);
    var legendOverflow = dataSeries.keys.any((element) => element.length > 20);
    var colorPalette = Theme.of(context).brightness == Brightness.light
        ? lightPalette
        : palette;
    return SfCartesianChart(
        axes: query.createAxes(dataSeries)?.sublist(1),
        tooltipBehavior: TooltipBehavior(
          enable: true,
        ),
        isTransposed: query.flipAxes != true,
        legend: Legend(
            position: legendOverflow ? LegendPosition.bottom : null,
            title: LegendTitle(
                text: request.safeGroupByVariable(query.groupByVariable) ??
                    'groups'),
            isVisible: dataSeries.keys.length > 1),
        primaryXAxis: xAxis,
        primaryYAxis: query.createAxes(dataSeries)?.firstOrNull,
        series: <ChartSeries>[
          ...dataSeries.keys.map((series) {
            return StackedBarSeries<DataPoint, dynamic>(
                name: series,
                sortFieldValueMapper: query.sortOn == null
                    ? null
                    : (data, index) => query.sortOn == 'x' ? data.x : data.y,
                sortingOrder: query.sortOn == null
                    ? null
                    : query.sortAscending == true
                        ? SortingOrder.ascending
                        : SortingOrder.descending,
                color: colorPalette[dataSeries.keys.length > 1 &&
                        dataSeries.keys.toList().indexOf(series) <
                            colorPalette.length
                    ? dataSeries.keys.toList().indexOf(series)
                    : (dataSeries.keys.toList().indexOf(series) %
                        colorPalette.length)],
                pointColorMapper: (DataPoint data, i) => colorPalette[
                    dataSeries.keys.length > 1 &&
                            dataSeries.keys.toList().indexOf(series) <
                                colorPalette.length
                        ? dataSeries.keys.toList().indexOf(series)
                        : xAxis is DateTimeAxis
                            ? 0
                            : (i % colorPalette.length)],
                legendItemText: series,
                yAxisName: query.yAxisNameForSeries(series, dataSeries),
                xAxisName: query.xAxisName,
                dataSource: dataSeries[series]!,
                xValueMapper: (DataPoint data, _) => data.x,
                yValueMapper: (DataPoint data, _) => data.y);
          })
        ]);```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

<img width="849" alt="Screenshot 2024-11-03 at 16 39 45" src="https://github.com/user-attachments/assets/bece91e9-3acf-4747-8439-9d4940990d63">

</details>


### Stack Traces

<details open><summary>Stack Traces</summary>

```dart
[Add the Stack Traces here]

On which target platforms have you observed this bug?

macOS

Flutter Doctor output

Doctor output
[Add your output here]
@VijayakumarMariappan VijayakumarMariappan added charts Charts component open Open labels Nov 4, 2024
@Baranibharathip
Copy link

Hi @Justus-M ,

We have checked the mentioned issue 'stacked bar series with categorical X-axis showing gap between bars' and tried to replicate it using the attached code snippet in SfCartesianChart with version 27.1.57 by,

  1. Ensured on Windows, Android, and web platforms.
  2. Ensured with empty point for Y value.
  3. Ensured with empty point for X value.
  4. Ensured with empty point for X,Y value.
  5. Ensured with series xAxisName and yAxisName property with multiple axes.

However, we were unable to reproduce it on our end. Please check the attached sample, and if you are still experiencing the issue, we request that you replicate it in the attached sample and provide us with more details regarding the specific scenario in which you are encountering this issue. This will help us to assist you more effectively.

Sample:
GH_2155.zip

Regards,
Baranibharathi P.

@LavanyaGowtham2021 LavanyaGowtham2021 added waiting for customer response Cannot make further progress until the customer responds. and removed open Open labels Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
charts Charts component waiting for customer response Cannot make further progress until the customer responds.
Projects
None yet
Development

No branches or pull requests

4 participants