1

I got the following Problem,

I would like to :

  • add a second Axis Caption to my Android Plot on the right side
  • same Labels like right.(maybe)
  • mark a line with a color and some text
  • the violet line should always be in front the yellow one

Is there any way to do this?

Because a picture says more than thousands of words.

enter image description here

Franz
  • 358
  • 6
  • 18

1 Answers1

1

There's not a built in second axis caption, but since they're just instances of TextLabelWidget its pretty easy to add your own. Here's an example that adds a label to the SimpleXYPlotActivity example

    TextLabelWidget textLabelWidget = new TextLabelWidget(
            plot.getLayoutManager(),
            "some text",
            null,  // TextLabelWidget instances "pack" to wrap the actual text size
            TextOrientation.VERTICAL_ASCENDING);

    textLabelWidget.getLabelPaint().setColor(Color.RED);
    textLabelWidget.getLabelPaint().setTextSize(PixelUtils.dpToPix(24));

    plot.getLayoutManager().add(textLabelWidget);
    textLabelWidget.position(
            // add a right margin of 4dp:
            PixelUtils.dpToPix(4), HorizontalPositioning.ABSOLUTE_FROM_RIGHT,

            // center the text with the plot space vertically:
            0, VerticalPositioning.ABSOLUTE_FROM_CENTER,

            // use the middle of the right edge of the text widget as the anchor:
            Anchor.RIGHT_MIDDLE);

Which produces:

enter image description here

Nick
  • 8,181
  • 4
  • 38
  • 63
  • Is there any possibility to add Labels to the 2nd Axis too? – Franz May 07 '18 at 13:56
  • sorry didnt notice there were multiple questions in here. Probably better to edit this question and create separate questions for the others, per SOF's rules. In any case, you can show labels for as many or as few edges as you like in the xml like this: `ap:lineLabels="left|bottom|top|right"` – Nick May 07 '18 at 14:42
  • Ok, I will remember it for the next time – Franz May 07 '18 at 15:07
  • Can I set ap:lineLabels via methodecall too? – Franz May 07 '18 at 15:08
  • You can: `plot.getGraph().setLineLabelEdges(XYGraphWidget.Edge.BOTTOM, XYGraphWidget.Edge.RIGHT);` – Nick May 07 '18 at 15:24