Skip to content

Commit 389616e

Browse files
committed
Align date/time labels towards vertical bottom
1 parent 90d5ec6 commit 389616e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

example/lib/main.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,18 @@ class _MyAppState extends State<MyApp> {
6161
trendLineColor: Colors.blueGrey[200]!,
6262
priceGridLineColor: Colors.blue[200]!,
6363
priceLabelStyle: TextStyle(color: Colors.blue[200]),
64-
timeLabelStyle: TextStyle(color: Colors.indigo),
64+
timeLabelStyle: TextStyle(color: Colors.blue[200]),
6565
selectionHighlightColor: Colors.red.withOpacity(0.2),
6666
overlayBackgroundColor: Colors.red[900]!.withOpacity(0.6),
6767
overlayTextStyle: TextStyle(color: Colors.red[100]),
68+
timeLabelHeight: 32,
6869
),
6970
overlayInfo: (candle) => {
7071
"💎": "🤚 ",
7172
"高": "${candle.high?.toStringAsFixed(2)}",
7273
"低": "${candle.low?.toStringAsFixed(2)}",
7374
},
74-
timeLabel: (timestamp, count) => "📅",
75+
timeLabel: (timestamp, count) => "<Date>",
7576
priceLabel: (price) => "${price.round()} 💎",
7677
),
7778
),

lib/chart_painter.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ class ChartPainter extends CustomPainter {
6868
)
6969
..textDirection = TextDirection.ltr
7070
..layout();
71-
timeTp.paint(canvas, Offset(x - timeTp.width / 2, params.chartHeight));
71+
72+
// Align texts towards vertical bottom
73+
final topPadding = params.style.timeLabelHeight - timeTp.height;
74+
timeTp.paint(
75+
canvas,
76+
Offset(x - timeTp.width / 2, params.chartHeight + topPadding),
77+
);
7278
}
7379
}
7480
}

0 commit comments

Comments
 (0)