This is a migrated thread and some comments may be shown as answers.

Custom ChartTooltipBehaviour

1 Answer 76 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Elton
Top achievements
Rank 1
Elton asked on 21 Jul 2014, 04:37 PM
Hello,

I can set the default tooltip as following, but I need to have a custom one consisting of data from both X-axis (DateTimeContinuousAxis)  and Y-axis (LinearAxis). Can you please provide with an example?

ChartTooltipBehavior tooltipBehavior = new ChartTooltipBehavior(this);
chart.getBehaviors().add(tooltipBehavior);

Thanks.

1 Answer, 1 is accepted

Sort by
0
Antony Jekov
Telerik team
answered on 23 Jul 2014, 02:37 PM
Hi Elton,

Thanks for writing.

The default behavior of the tooltip is to display both the category and the value of the selected data point. You don't need to customize it to achieve that.

The problem you are facing, I assume, is that you cannot see the tooltip at all, which might be a result of having a Calendar for category. If you are using some sort of date time axis you will be in this scenario.

You need to provide a way for the Calendar to be translated to String, so that the tooltip knows what to do with it, since the Calendar is a bit more specific that the other value types.

You can use something like this:
ChartTooltipBehavior tooltipBehavior = new ChartTooltipBehavior(this);
        tooltipBehavior.contentAdapter().setCategoryToStringConverter(new Function<Object, String>() {
            SimpleDateFormat format = new SimpleDateFormat("MMM dd");
 
            @Override
            public String apply(Object argument) {
                return format.format(((Calendar) argument).getTime());
            }
        });
 
        chartView.getBehaviors().add(tooltipBehavior);
You can set whatever format you want this way.

Please let me know if this works for you. I hope it answers your question, but please feel free to add to this ticket should you need any further assistance.

Thank you for your time and all best!

Regards,
Antony Jekov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussion
Asked by
Elton
Top achievements
Rank 1
Answers by
Antony Jekov
Telerik team
Share this question
or