Put legend on the top right corner of the plot area

Thank you for providing us excellent chart library!

Is it possible that putting the legend on the top right corner of the plot area?

I tried like this... but, right alignment doesn't work.

  Legend _getLegend() {
return Legend(
isVisible: true,
position: LegendPosition.top,
alignment: ChartAlignment.far, //ignored??
offset: Offset(10, 0),
overflowMode: LegendItemOverflowMode.scroll,
width: '200%',
toggleSeriesVisibility: false,
);
}



3 Replies

YG Yuvaraj Gajaraj Syncfusion Team June 2, 2022 03:24 PM UTC

Hi Ai,


Greetings from Syncfusion. We suggest you modify the offset value of the legend then it moves to the specified location. If the offset value is 0 then the legend renders in the default location based on the position, for example, if the legend position is top, then it gets rendered in the top center of the chart. So, if you wish to move the legend to the end in the plot area then increase the offset value. We have attached the code snippet below to achieve your requirement.


Screenshot:

Chart, line chart

Description automatically generated


Code snippet:

legend: Legend(

  isVisible: true,

  position: LegendPosition.top,

  offset: const Offset(150, 0),                              

),


Demo sample: https://flutter.syncfusion.com/#/cartesian-charts/legend/legend-with-various-options


Regards,

Yuvaraj.



AI ai June 3, 2022 03:04 AM UTC

Thank you for the reply.

The string on the legend is variable, so I cannot determine the offset value..

I will consider other solutions.



YG Yuvaraj Gajaraj Syncfusion Team June 6, 2022 04:33 PM UTC

Hi Ai,


If you want to move the legend you need to set the offset based on the legend string, or you can achieve this kind of appearance with the help of the annotation property in the chart. You can position the custom widget in the chart area, but the entire functionality of the legend will not be achieved with this, you can have the same appearance using this. We have attached the UG and Demo sample link below to achieve the annotation in the chart.


UG: https://help.syncfusion.com/flutter/cartesian-charts/annotations


Sample: https://flutter.syncfusion.com/#/cartesian-charts/series-features/annotation/chart-with-watermark


Regards,

Yuvaraj.


Loader.
Up arrow icon