Rakesh
Rakesh

Reputation: 1

How to add average indicator in flutter SfCartesianChart?

I am using SfCartesianChart in flutter, The bars are created. How to add the average values indicator horizontally? I have added this code also from its official site, but the average indicator is not visible.

SfCartesianChart(
    onAxisLabelTapped: (valu) {
      print("axislable tapped");
    },
    primaryXAxis: CategoryAxis(),
    legend: Legend(isVisible: true),
    indicators: <TechnicalIndicators<
        BudgetData, dynamic>>[
      AccumulationDistributionIndicator<
              BudgetData, dynamic>(
          isVisible: true,
          signalLineColor: Colors.blue,
          dataSource: _budgetController
              .filteredBudgetDataSourceDetails,
          lowValueMapper:
              (BudgetData sales, _) =>
                  sales.amount,
          highValueMapper:
              (BudgetData sales, _) =>
                  sales.amount,
          closeValueMapper:
              (BudgetData sales, _) =>
                  sales.amount,
          seriesName: 'HiloOpenClose')
    ],
    primaryYAxis: NumericAxis(
      isVisible: false,
      minimum: 0,
      maximum: _budgetController
          .budgetChartMaxValueDetails
          .value,
      interval: 100,
    ),
    series: <ColumnSeries<BudgetData,
        String>>[
      ColumnSeries<BudgetData, String>(
        dataSource: _budgetController
            .filteredBudgetDataSourceDetails,
        gradient: const LinearGradient(
          colors: <Color>[
            Colors.blue,
            Colors.red,
            Colors.green
          ],
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
        ),
        borderRadius:
            BorderRadius.circular(10),
        xValueMapper:
            (BudgetData data, _) {
          if (_isFilterByYear) {
            return data.year.toString();
          } else {
            // Concatenate year and month to differentiate data for each month
            return '${data.month}\n${data.year}';
          }
        },
        selectionBehavior: selection,
        yValueMapper:
            (BudgetData data, _) =>
                data.amount,
        dataLabelSettings:
            const DataLabelSettings(
                isVisible: true),
        onPointTap: (ChartPointDetails
            details) async {
          ////////////click
          setState(() {
            _isLoading = true;
          });

          String selectedMonth =
              _budgetController
                  .filteredBudgetDataSourceDetails[
                      details
                          .pointIndex!]
                  .month;
          int selectedYear =
              _budgetController
                  .filteredBudgetDataSourceDetails[
                      details
                          .pointIndex!]
                  .year;

          //get month's transactions
          bool isDone =
              await _expenseController
                  .fetchMonthTransactions(
                      month: getMonthIndex(
                          selectedMonth),
                      year:
                          selectedYear);

          if (mounted) {
            setState(() {
              _isLoading = isDone;
            });
          }
          ////////////////
        },
      ),
    ],
  )

I have tried from its official site but the indicator is not visible.

Upvotes: 0

Views: 42

Answers (0)

Related Questions