Pre loader

Customizing Legend Fonts & Colors

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

Answered
0
0

Hello,

I’m probably missing something obvious, but how can I change the font/colors of JUST the scichart legend (not axes labels or other text) in Android.

Thank you.

Version
4.3.0.4646
  • You must to post comments
Best Answer
0
0

Hi there,

Well to do this you’ll need to create custom LegendItem or extend default one and override font and colors. Then you need to create factory for new items:

    class CustomLegendItemFactory extends DefaultLegendItemsFactory {
    @Override
    protected LegendItemBase createLegendItem(View legendItemView) {
        return new CustomLegendItem(legendItemView);
    }

    public static class CustomLegendItem extends DefaultLegendItem {
        public CustomLegendItem(View itemView) {
            super(itemView);
        }

        @Override
        public void bindSource(Object source, SciChartLegend legend) {
            super.bindSource(source, legend);

            // change TextView properties of item
            name.setTextColor(Color.RED);
            name.setTypeface(Typeface.MONOSPACE);
        }
    }
}

After that just need to use new factory during creation of LegendModifier and pass it into chart:

  LegendModifier legendModifier = new LegendModifier(new SciChartLegend(getActivity()), new SeriesInfoLegendAdapter(new CustomLegendItemFactory()), true);
  legendModifier.setLegendPosition(Gravity.TOP | Gravity.START, 16);
  Collections.addAll(surface.getChartModifiers(), sciChartBuilder.newModifierGroup()
                    .withModifier(legendModifier)
                    .build());

Is this suitable for your needs?

Best regards,
Yura

  • C Bolton
    That’s what I needed. Thank you!
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies