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

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.