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

Single tooltip for stacked barchart

2 Answers 55 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alex
Top achievements
Rank 1
Alex asked on 12 May 2015, 03:04 PM
Is it possible to have a single tooltip that will display, at the top of the stack, aggregated data from all parts of the stacked bar, no matter what part the user touches.Also, how do I add the % sign to the Y LinearAxis of the chart. I guess setStringFormat on the LinearAxis object is the way to go, but cannot figure out the format syntax.

2 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 12 May 2015, 03:05 PM
Please delete the two extra duplicate posts. It was reporting a failure when I was trying to post, while it actually did post the message
0
Victor
Telerik team
answered on 15 May 2015, 08:46 AM
Hi Alexandar,

Thanks for the questions.
You can call setLabelFormat() with a java format string.
To display aggregate data in the tooltip you have to provide a custom tooltip adapter. For example:
public class CustomTooltipAdapter extends ChartTooltipContentAdapter {
    CategoricalAxis axis;
    public CustomTooltipAdapter(Context context, CategoricalAxis axis) {
        super(context);
        this.axis = axis;
    }
    @Override
    public View getView(Object[] targets) {
        Object category = ((CategoricalDataPoint)targets[0]).getCategory();
        List<DataPoint> points = axis.getDataPointsForValue(category);
        LinearLayout tooltipContainer = new LinearLayout(this.context);
        tooltipContainer.setOrientation(LinearLayout.VERTICAL);
        TextView categoryView = new TextView(this.context);
        categoryView.setBackgroundColor(Color.BLACK);
        categoryView.setTextColor(Color.WHITE);
        categoryView.setText(String.format("Category: %s", category.toString()));
        tooltipContainer.addView(categoryView);
        for(DataPoint point : points) {
            tooltipContainer.addView(createViewForPoint((CategoricalDataPoint)poi
        }
        return tooltipContainer;
    }
    private View createViewForPoint(CategoricalDataPoint point) {
        BarSeries series = (BarSeries)point.getParent().getPresenter();
        TextView pointView = new TextView(this.context);
        pointView.setBackgroundColor(series.getLegendFillColor());
        pointView.setText(String.format("Value: %f.2", point.getValue()));
        return pointView;
    }
}
This assumes that you are using CategoricalAxis. If you are using DateTimeContinuousAxis you will have make a few modifications.

Please write again if you need further assistance.

Regards,
Victor
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Victor
Telerik team
Share this question
or