SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on where you can earn rep for your questions!


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.

Anyway I’ve logged your request into our bugtracker and we’ll try to improve LegendModifier API in one of our future releases.

Best regards,

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.