Skip to main content

LineChartAppi

A powerful line chart widget for displaying time-series data and trends with support for multiple data series, interactive features, and customizable styling.

Features

  • Multiple Data Series: Display multiple lines on the same chart
  • Interactive Elements: Touch interactions, zoom, and pan capabilities
  • Customizable Styling: Control line colors, thickness, and point styles
  • Grid and Axes: Configurable grid lines and axis labels
  • Animation: Smooth animations for data updates
  • Responsive Design: Adapts to different screen sizes
  • Data Points: Optional data point markers with custom styling

Usage

Basic Usage

LineChartAppi(
data: [
LineChartData(
points: [
FlSpot(0, 1),
FlSpot(1, 3),
FlSpot(2, 2),
FlSpot(3, 5),
],
color: Colors.blue,
),
],
)

Advanced Usage

LineChartAppi(
data: multipleDataSeries,
showGrid: true,
enableInteraction: true,
animationDuration: Duration(milliseconds: 1500),
xAxisTitle: 'Time',
yAxisTitle: 'Value',
onPointTap: (lineIndex, pointIndex, point) {
print('Tapped point: ${point.x}, ${point.y}');
},
)

Parameters

NameTypeDescriptionDefault
dataList<LineChartData>Required. List of data series to display-
showGridbool?Whether to show grid linestrue
enableInteractionbool?Enable touch interactionstrue
animationDurationDuration?Duration of chart animationsDuration(milliseconds: 1000)
xAxisTitleString?Title for the X-axisnull
yAxisTitleString?Title for the Y-axisnull
minXdouble?Minimum X-axis valueAuto-calculated
maxXdouble?Maximum X-axis valueAuto-calculated
minYdouble?Minimum Y-axis valueAuto-calculated
maxYdouble?Maximum Y-axis valueAuto-calculated
onPointTapFunction(int, int, FlSpot)?Callback when a point is tappednull
backgroundColorColor?Background color of the chartColors.transparent
gridColorColor?Color of the grid linesColors.grey.shade300
showDataPointsbool?Whether to show data point markersfalse
lineWidthdouble?Default line thickness2.0

LineChartData Model

class LineChartData {
final List<FlSpot> points;
final Color color;
final double? lineWidth;
final bool showDataPoints;
final String? label;

LineChartData({
required this.points,
required this.color,
this.lineWidth,
this.showDataPoints = false,
this.label,
});
}

FlSpot Model

class FlSpot {
final double x;
final double y;

FlSpot(this.x, this.y);
}

Best Practices

  1. Data Organization: Organize data points in chronological or logical order
  2. Color Selection: Use distinct colors for multiple data series
  3. Performance: Limit the number of data points for smooth performance
  4. Axis Scaling: Set appropriate min/max values for better visualization
  5. Interaction: Enable interactions for better user experience
  6. Labels: Provide meaningful axis titles and series labels

Examples

Simple Line Chart

LineChartAppi(
data: [
LineChartData(
points: [
FlSpot(0, 10),
FlSpot(1, 15),
FlSpot(2, 12),
FlSpot(3, 18),
FlSpot(4, 20),
],
color: Colors.blue,
label: 'Sales',
),
],
xAxisTitle: 'Month',
yAxisTitle: 'Revenue (K)',
)

Multiple Data Series

LineChartAppi(
data: [
LineChartData(
points: salesData,
color: Colors.blue,
label: 'Sales',
lineWidth: 3.0,
),
LineChartData(
points: expenseData,
color: Colors.red,
label: 'Expenses',
lineWidth: 3.0,
),
],
showGrid: true,
enableInteraction: true,
)

Interactive Chart with Data Points

LineChartAppi(
data: chartData,
showDataPoints: true,
onPointTap: (lineIndex, pointIndex, point) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Data Point'),
content: Text('Value: ${point.y} at ${point.x}'),
),
);
},
)