Pre loader

Separate Legend from ChartSurface

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums


I managed to spearate the legend from the SciChartSurface, however the way I did it is very hackish. I couldn’t find any documentation on how it is supposed to be done correctly.

The way I did it (Kotlin code):

val legend = SciChartLegend(context)
legendModifier = LegendModifier(legend)
legendModifier.setLegendPosition(Gravity.START or Gravity.TOP, 0)

val modifierGroup = chartBuilder.newModifierGroup().build()

if(legend.parent != null)
    (legend.parent as ViewGroup).removeView(legend)

val linearLayout = LinearLayout(context)
linearLayout.orientation = LinearLayout.VERTICAL

I was surprised that passing the legend to LegendModifier constructor also adds it to it’s layout. So I had to manually remove it and add it to my LinearLayout. It does work, but as I said, it is a hackish way of doing it. My question is, how is it done correctly?

  • You must to post comments

Hi Miha,

Well unfortunately it is a default behavior of LegendModifier and it will be hard to change because:

  1. When it is added into modifier collection it becomes part of SciChartSurface so it has access only to the chart and its subviews and it can place it only there.
  2. LegendModifier has properties which are responsible for legend placement inside parent ViewGroup and they probably won’t work properly with other ViewGroup container.

The purpose of constructor which accepts SciChartLegend is to allow customization of legend appearance (e.g. you can configure some legend properties before passing it to the modifier or you can subclass it if you want )

Alternative to using LegendModifier is creating and managing content of SciChartLegend on your own but it will require writing of code for creating and placing SciChartLegend in your app, creating LegendItemsAdapter and filling it with data from chart, creating listeners for different chart events (e.g. renderable series was added/removed, series name, color, visibility changed etc) and updating data when something in chart changes. I wouldn’t say that it would be easy to do this.


We’ve changed behavior of constructor which accepts SciChartLegend instance in v2.1. Now when you’re using this constructor it’s expected that legend will be placed somewhere in layout:

<LinearLayout xmlns:android=""

    android:layout_height="0dp" android:layout_weight="1" />



and then legend instance will be passed into LegendModifier:

    final LegendModifier legendModifier = new LegendModifier(legend);

In this case LegendModifier’s properties which are responsible for placing legend within chart won’t work.

To support previous case when you just need to customize SciChartLegend appearance you can use new constructor which accepts useAutoPlacement flag:

    final LegendModifier legendModifier = new LegendModifier(legend, new SeriesInfoLegendAdapter(), true);

Best regards,

  • Dinesh Sheoran
    Expecting fix above issue from scichart very soon !
  • Yura Khariton
    Actually it was fixed in v2.1 during work on pie/donut charts ( we needed to place legend outside chart in demo examples for these chart types ). Also I updated my answer. Hope this will help you!
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.