Syncfuction Hilo Series has high and low values and it automatically shows values as high and low label names. I want to change these label names to another language. Here is part of code of my work and how it looks like tooltip.
SfCartesianChart(
title: ChartTitle(
text: 'En düşük ve en yüksek oranlar',
alignment: ChartAlignment.near,
textStyle: TextStyle(
color: blueLogo,
fontSize: 12.sp,
)),
legend: Legend(
isVisible: true,
position: LegendPosition.top,
overflowMode: LegendItemOverflowMode.wrap),
tooltipBehavior: TooltipBehavior(enable: true),
primaryXAxis: CategoryAxis(
labelIntersectAction:
AxisLabelIntersectAction.multipleRows),
primaryYAxis: NumericAxis(maximum: 150, plotBands: [
PlotBand(
start: 80,
end: 80,
borderColor: Colors.red,
borderWidth: 1,
),
PlotBand(
start: 120,
end: 120,
borderColor: Colors.red,
borderWidth: 1,
)
]),
series: <ChartSeries>[
HiloSeries<ChartData, String>(
markerSettings: const MarkerSettings(isVisible: true),
name: 'Oranlar',
enableTooltip: true,
dataSource: chartData,
xValueMapper: (ChartData data, _) => data.unit,
lowValueMapper: (ChartData data, _) => data.low,
highValueMapper: (ChartData data, _) => data.high)
])
Output of this code sample
How can I change these high and low label names?
You can change the TooltipBehaviour of the chart and construct the tooltip widget yourself. Official syncfusion documentation is here.
Related
Need to show no data available text in place of bar which has zero value , y axis labels are
string and x axis are integers
please refer below for the 1st image is acutal result and 2nd image is expected result . 1st image in which empty place which has zero value instead of empty place need to show no data available text
SfCartesianChart(
crosshairBehavior: _crosshairBehavior,
primaryXAxis: CategoryAxis(
majorTickLines: MajorTickLines(size: 20, width: 0),
axisBorderType: AxisBorderType.withoutTopAndBottom,
labelAlignment: LabelAlignment.center,
borderWidth: 2.0,
labelStyle: TextStyle(
fontFamily: 'Roboto',
fontSize: 14,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w500),
//maximumLabelWidth: 100,
labelPosition: ChartDataLabelPosition.outside,
borderColor: Colors.blueGrey[800]),
primaryYAxis: CategoryAxis(
plotBands: <PlotBand>[
PlotBand(
isVisible: widget.isFleetAverageVisible,
start: 30,
end: 29,
borderWidth: 0.3,
borderColor: Colors.black,
)
],
interval: 25,
maximumLabels: 4,
maximum: 100,
minimum: 0,
majorTickLines: MajorTickLines(size: 15, width: 0),
majorGridLines: MajorGridLines(dashArray: [5, 5]),
),
series: stackedWidget(sortSelected != null
? sortSelected == true
? SortingOrder.ascending
: SortingOrder.descending
: SortingOrder.none),
legend: Legend(
isVisible: true,
position: LegendPosition.bottom,
overflowMode: LegendItemOverflowMode.wrap,
),
onLegendTapped: (LegendTapArgs args) {
},
),
List<ChartSeries> stackedWidget(SortingOrder sortingOrder) {
return <ChartSeries>[
StackedBarSeries<ChartData, String>(
sortingOrder: sortingOrder,
legendIconType: LegendIconType.horizontalLine,
legendItemText: "series1",
width: 0.3,
spacing: 0.2,
dataSource: chartData,
//list of data
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y1,
sortFieldValueMapper: (ChartData sales, _) => sales.y1,
color: Color.fromRGBO(51, 102, 255, 1))
];
}
Try giving the DataLabelSettings() to the dataLabelSettings: property on StackedBarSeries():
List<ChartSeries> stackedWidget(SortingOrder sortingOrder) {
return <ChartSeries>[
StackedBarSeries<ChartData, String>(
dataLabelSettings: DataLabelSettings(
builder: (
data,
point,
series,
pointIndex,
seriesIndex,
) {
if (chartData[pointIndex].y == 0 || chartData[pointIndex].y == null) {
return Row(children: const [
Icon(Icons.warning_amber_outlined),
Text("No data available"),
]);
} else {
return const SizedBox();
}
},
isVisible: true,
),
sortingOrder: sortingOrder,
legendIconType: LegendIconType.horizontalLine,
legendItemText: "series1",
width: 0.3,
spacing: 0.2,
dataSource: chartData,
//list of data
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y1,
sortFieldValueMapper: (ChartData sales, _) => sales.y1,
color: Color.fromRGBO(51, 102, 255, 1))
];
}
how to flutter syncfusion bar chart background grid line delete?
use pub.dev // syncfusion_flutter_charts 19.4.56
https://pub.dev/packages/syncfusion_flutter_charts
< image grid line (grey color line) >
my code
return SfCartesianChart(
title: ChartTitle(text: totalTaxString, textStyle: const TextStyle(fontWeight: FontWeight.bold)),
primaryXAxis: CategoryAxis(
maximumLabelWidth: MediaQuery.of(context).size.width > 480 ? MediaQuery.of(context).size.width * 0.3 : 100,
labelStyle: const TextStyle(overflow: TextOverflow.ellipsis)
// isVisible: false
),
primaryYAxis: CategoryAxis(
isVisible: false
),
series: <BarSeries>[
BarSeries<ModelPioChartData, String>(
dataSource: listPioChartData,
pointColorMapper:(ModelPioChartData data, _) => data.color,
xValueMapper: (ModelPioChartData data, _) => data.x,
yValueMapper: (ModelPioChartData data, _) => data.y,
dataLabelMapper: (ModelPioChartData data, _) {
if(data.y.toStringAsFixed(0).length > 4) {
return "${data.y/10000}조 원";
} else {
return "${data.y.toStringAsFixed(0)}억 원";
}
},
dataLabelSettings: const DataLabelSettings(
isVisible: true
),
enableTooltip: true,
),
],
);
I suggest you use the majorGridLines property in the axis, you can customize the width, color, and size of the major grid line. We have attached the code snippet and UG below for your reference.
primaryXAxis:
CategoryAxis(
majorGridLines: const MajorGridLines(width: 0)
),
UG: https://help.syncfusion.com/flutter/cartesian-charts/axis-customization#grid-lines-customization
Now: My goal:
I am using the syncfusion_flutter_charts package to display the chart and that table view is so annoying. How to remove that? or how to do this kind of chart using custom widgets?
// child of some widgets like container
child: SfCartesianChart(
primaryXAxis: CategoryAxis(),
legend: Legend(isVisible: false),
tooltipBehavior: TooltipBehavior(enable: true),
series: <ChartSeries<_SalesData, String>>[
LineSeries<_SalesData, String>(
dataSource: data,
xValueMapper: (_SalesData sales, _) =>sales.year.toString(),
yValueMapper: (_SalesData sales, _) =>sales.value,
),
],
),
You can customize you chart, You can use this. I use map for test and date for example ({"val": 100, "year": 2000}), so you can use your favorite type, Set or anything else.
SfCartesianChart(
primaryXAxis: CategoryAxis(
isVisible: false,
),
primaryYAxis: CategoryAxis(
isVisible: false,
),
plotAreaBorderWidth: 0,
backgroundColor: Colors.grey[200],
legend: Legend(isVisible: false),
tooltipBehavior: TooltipBehavior(enable: true),
series: <ChartSeries<Map, String>>[
FastLineSeries<Map, String>(
width: 2,
dataSource: [{"val": 100, "year": 2000}, ...],
color: Colors.green,
yValueMapper: (Map sales, _) => sales['val'],
xValueMapper: (Map sales, _) => sales['year'].toString(),
),
],
),
I have a SfCartesianChart which displays a line chart of a list of values from 0 to 100, i.e. percentages. However, when there is a data point, for example, 99%, the upper limit of the y-axis seems like 120% which does not mean anything.
Here is my chart code
SfCartesianChart(
margin: EdgeInsets.all(0),
borderWidth: 0,
plotAreaBorderWidth: 0,
title: ChartTitle(text: 'Mood Tracks', textStyle: TextStyle(fontWeight: FontWeight.bold)),
tooltipBehavior: _tooltipBehavior,
series: <ChartSeries>[
LineSeries<MoodRecord, dynamic>(
name: 'Moods',
color: Colors.green[400],
dataSource: records,
xValueMapper: (MoodRecord record, _) => record.date,
yValueMapper: (MoodRecord record, _) => record.mood.toInt(),
dataLabelSettings: DataLabelSettings(isVisible: false),
enableTooltip: true,
animationDuration: 2000,
markerSettings: MarkerSettings(
isVisible: true,
shape: DataMarkerType.circle,
color: kPrimaryColor
)
)
],
primaryXAxis: CategoryAxis(
labelPlacement: LabelPlacement.onTicks,
labelStyle: TextStyle(fontWeight: FontWeight.bold)
),
primaryYAxis: NumericAxis(
labelFormat: '{value}%',
labelStyle: TextStyle(fontWeight: FontWeight.bold)
),
),
Is there any way to define an upper limit on the y-axis? I do not want my chart to display something like 120% on the y-axis.
If there any better way to display percentages, it would also be appreciated.
We have looked over the question and code and can inform you that the axis range is determined by the data source values. If you don't want values above 100 to be shown, use the maximum property in the axis and manually customize the range. For more details, see the help document. You may also use the numberFormat property to reflect percentage values, as seen in the example below.
https://www.syncfusion.com/kb/11519/how-to-apply-the-currency-format-to-the-axis-labels-sfcartesianchart
For 100 percent stacked charts, refer to the support document, which converts the given data to 100 percent.
SfCartesianChart(
primaryXAxis: CategoryAxis(labelStyle: const TextStyle(
color: Colors.white,
fontFamily: 'Roboto',
fontSize: 10,
)),
primaryYAxis: NumericAxis(
**minimum: 0, maximum: 100, interval: 25,**
labelFormat: '{value}%',
labelStyle: const TextStyle(
color: Colors.white,
fontFamily: 'Roboto',
fontSize: 10,
)),
I am using the syncfusion library for Flutter and I can build a line chart when I have data. However, if the list is empty, it simply draws axes and that is all. Even though this is expected, I want to write a "No Data" message in the center of the chart.
Here is my chart widget:
SfCartesianChart(
margin: EdgeInsets.all(0),
borderWidth: 0,
plotAreaBorderWidth: 0,
title: ChartTitle(text: 'Mood Tracks', textStyle: TextStyle(fontWeight: FontWeight.bold)),
tooltipBehavior: _tooltipBehavior,
series: <ChartSeries>[
LineSeries<MoodRecord, dynamic>(
name: 'Moods',
color: Colors.green[400],
dataSource: [],
xValueMapper: (MoodRecord record, _) => record.date,
yValueMapper: (MoodRecord record, _) => record.mood.toInt(),
dataLabelSettings: DataLabelSettings(isVisible: true),
enableTooltip: true)
],
primaryXAxis: CategoryAxis(
labelPlacement: LabelPlacement.onTicks,
labelStyle: TextStyle(fontWeight: FontWeight.bold)
),
primaryYAxis: NumericAxis(
labelFormat: '{value}%',
labelStyle: TextStyle(fontWeight: FontWeight.bold)
),
),
Is there any way to show such message?
We have looked through the question and like to tell you that we can meet the requirement by using the chart's annotations property. We can position the Text Widget with ‘No Data' if the data source is empty, otherwise, we can allocate the empty container to the annotations. Using these annotations, we can place the necessary widget in the required position in the map, and for more detail, see the support document and we have attached the sample as a reference.
Sample: https://www.syncfusion.com/downloads/support/directtrac/326033/ze/I326033_no_data_text48946494