Single tooltip for stacked barchart

3 posts, 0 answers
  1. Alex
    Alex avatar
    54 posts
    Member since:
    Feb 2009

    Posted 12 May 2015 Link to this post

    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. Alex
    Alex avatar
    54 posts
    Member since:
    Feb 2009

    Posted 12 May 2015 in reply to Alex Link to this post

    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
  3. DevCraft banner
  4. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 15 May 2015 Link to this post

    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
Back to Top