Ad
Flutter Show Y Axis Values As String
I have a simple graph in which I have x-axis as string and y-axis as int but my values are too long 10000 I need to show it as 10k
My code
Container(
height: MediaQuery.of(context).size.height * 0.25,
child: SfCartesianChart(
enableAxisAnimation: true,
primaryXAxis: CategoryAxis(
majorGridLines: MajorGridLines(width: 0),
//Hide the axis line of x-axis
axisLine: AxisLine(width: 0),
interval: 1),
primaryYAxis: NumericAxis(
minimum: 0, maximum: highSale,
interval: highSale < 200 ? 100 : 2000,
majorGridLines: MajorGridLines(width: 0),
//Hide the axis line of x-axis
axisLine: AxisLine(width: 0),
),
tooltipBehavior: _tooltip,
plotAreaBorderWidth: 0,
legend: Legend(isVisible: false),
series: <ChartSeries<_ChartData, String>>[
ColumnSeries<_ChartData, String>(
dataSource: weekly
? data
: yearly
? dataMonth
: monthly
? dataDaily
: daily
? dataDaily
: [],
xValueMapper: (_ChartData data, _) => data.x,
yValueMapper: (_ChartData data, _) => data.y,
pointColorMapper: (_ChartData data, _) => data.color,
name: 'Week',
color: weekly ? kPrimaryColor : Colors.red)
]),
),
In the image you can see it's showing 36000 I need to show it as 36k I try to convert it to k value but the issue is on yValueMapper it's showing string isn't allowed. So what I was thinking is maybe there is some value to show mapper? like graph will work on value mapper and text will be different.
Ad
Answer
The above answer is correct but you need to format the primary axis
Like this
primaryYAxis: NumericAxis(
numberFormat: NumberFormat.compact(),
)
Ad
source: stackoverflow.com
Related Questions
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?
Ad