1

In the Syncfusion chart, text style of axis label can be initially changed depending on the pointIndex of any of the label?

The code I use has a separate widget on the data label. But I can't change the names in XValueMapper.

To make it clearer, below is an example of a piece of code I use:

SfCartesianChart(
        title: ChartTitle(
          text: title,
          backgroundColor: titleBackColor,
          textStyle: titleStyle,
        ),
        selectionGesture: ActivationMode.singleTap,
        selectionType: SelectionType.point,
        series: <ChartSeries>[
          StackedBar100Series<RankingChartData, String>(
              dataLabelSettings: DataLabelSettings(
                builder: (
                  data,
                  point,
                  series,
                  pointIndex,
                  seriesIndex,
                ) {
                  if (chartData[pointIndex].name.contains(name!)) {
                    return Padding(
                      padding: EdgeInsets.only(right: 150.0.w),
                      child: Icon(
                        Icons.check_box,
                        color: primary.base,
                      ),
                    );
                  } else {
                    return const SizedBox();
                  }
                },
                isVisible: true,
              ),
              dataSource: chartData,
              selectionBehavior: _selectionBehavior,
              xValueMapper: (RankingChartData exp, _) => exp.name,
              yValueMapper: (RankingChartData exp, _) => exp.positive,
              color: positiveColor ?? Colors.green,
              sortingOrder: sort ? SortingOrder.ascending : null,
              sortFieldValueMapper:
                  sort ? (RankingChartData exp, _) => exp.positive : null,
              onPointTap: (d) {
                showDialog(
                    context: (context),
                    builder: (context) {
                      return AlertDialog(
                        title: Text(chartData[d.pointIndex!].name),
                        content: Text.rich(TextSpan(children: [
                          const TextSpan(text: "Positive\n"),
                          TextSpan(
                            text: chartData[d.pointIndex!].positive.toString(),
                            style: TextStyle(
                              color: positiveColor ?? Colors.green,
                              fontSize: 20.sp,
                            ),
                          ),
                        ])),
                      );
                    });
              }),
        ],
        primaryXAxis: CategoryAxis(),
      ),

0 Answers0