Question

I created an bar chart using android plot.

I want that, after clicking a bar, its matching domain label would change color.

I know how to set all of the domain label colors . using:

 plot.getGraphWidget().getDomainLabelPaint().setColor(Color.WHITE);

but I would like to change the color of just one of the labels.

My domain step is:

 plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1);

I changed the domain's format with this:

  plot.setDomainValueFormat(new Format() {

        @Override
        public StringBuffer format(final Object obj,
                final StringBuffer toAppendTo, final FieldPosition pos) {
            final int index = ((Number) obj).intValue();
            return new StringBuffer("").append((char) (index + 'A'));
        }

        @Override
        public Object parseObject(final String string,
                final ParsePosition position) {
            return null;
        }

    });

I have two ideas (which I fail to do):

1) can I change the color of a domain label string, by extending the Format class (in the methods above)? OR 2) can I draw another set of of domain labels on top of the existing ones?(that would be with different color)

Is there another way?

Was it helpful?

Solution

The next build of Androidplot will contain a new class and a couple new methods that can be used to accomplish this. For now, here's a development build that contains this new functionality. The new class is com.androidplot.util.Mapping and the new methods of interested will be added to com.androidplot.xy.XYGraphWidget. They are:

public void setDomainLabelPaintMap(Mapping<Paint, Number> domainLabelPaintMap)
public void setRangeLabelPaintMap(Mapping<Paint, Number> rangeLabelPaintMap)

Here's a quick example of how they can be used:

plot.getGraphWidget().setRangeLabelPaintMap(new Mapping<Paint, Number>() {

    private Paint customPaint;

    {
        // configure Paint instances either programmatically
        // (as shown here) or use Configurator to initialize via XML.
        customPaint = new Paint();
        customPaint.setColor(Color.RED);
    }

    @Override
    public Paint get(Number number) {
        if(number.doubleValue() > 1) {
            return customPaint;
        }
        return null;
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top