SfSparkLineChart.custom constructor

SfSparkLineChart.custom({
  1. Key? key,
  2. int? dataCount,
  3. SparkChartIndexedValueMapper? xValueMapper,
  4. SparkChartIndexedValueMapper<num>? yValueMapper,
  5. SparkChartPlotBand? plotBand,
  6. double width = 2,
  7. List<double>? dashArray,
  8. Color? color,
  9. bool isInversed = false,
  10. double axisCrossesAt = 0,
  11. Color? axisLineColor,
  12. double axisLineWidth = 2,
  13. List<double>? axisLineDashArray,
  14. Color? highPointColor,
  15. Color? lowPointColor,
  16. Color? negativePointColor,
  17. Color? firstPointColor,
  18. Color? lastPointColor,
  19. SparkChartTrackball? trackball,
  20. SparkChartMarker? marker,
  21. SparkChartLabelDisplayMode? labelDisplayMode,
  22. TextStyle? labelStyle,
})

Creates the sparkline chart for the provided set of data with its default view.

The difference between the default constructor and this constructor is, in the default constructor uses its data property to get the input data value. The data property of the default constructor is of type List

The custom constructor uses its dataCount, xValueMapper and yValueMapper to get the input data.

The dataCount property allows declaring the total data count going to be displayed in the chart.

The xValueMapper returns the x value of the corresponding data point. The xValueMapper allows providing num, DateTime, or string as x-value.

The yValueMapper returns the y-value of the corresponding data point.

class SalesData {
  SalesData(this.month, this.sales);
  final String month;
  final double sales;
}

List<SalesData> data;

@override
void initState() {
 super.initState();
 data = <SalesData>[
   SalesData('Jan', 200),
   SalesData('Feb', 215),
   SalesData('Mar', 380),
   SalesData('Apr', 240),
   SalesData('May', 280),
 ];
}

 @override
Widget build(BuildContext context) {
 return Scaffold(
   body: Center(
       child: SfSparkLineChart.custom(
        dataCount: 5,
         xValueMapper: (int index) => data[index].month,
         yValueMapper: (int index) => data[index].sales
        )
      ),
  );
}

Implementation

SfSparkLineChart.custom(
    {Key? key,

    /// Data count for the spark charts.
    int? dataCount,

    /// Specifies the x-value mapping field.
    SparkChartIndexedValueMapper<dynamic>? xValueMapper,

    /// Specifies the y-value maping field.
    SparkChartIndexedValueMapper<num>? yValueMapper,
    this.plotBand,
    this.width = 2,
    this.dashArray,
    this.color,
    this.isInversed = false,
    this.axisCrossesAt = 0,
    this.axisLineColor,
    this.axisLineWidth = 2,
    this.axisLineDashArray,
    this.highPointColor,
    this.lowPointColor,
    this.negativePointColor,
    this.firstPointColor,
    this.lastPointColor,
    this.trackball,
    this.marker,
    this.labelDisplayMode,
    this.labelStyle})
    : _sparkChartDataDetails = SparkChartDataDetails(
          dataCount: dataCount,
          xValueMapper: xValueMapper,
          yValueMapper: yValueMapper),
      super(key: key);