3

I'm using candlestick chart of androidplot library.meeting problems to show open and close values/labels alongwith the sticks.Here is the solution i found.

 final LineAndPointFormatter lpf = new LineAndPointFormatter(null, null, null, null);
    PointLabelFormatter pointLabelFormatter=new PointLabelFormatter();
   // pointLabelFormatter.hOffset=150;
    //pointLabelFormatter.vOffset=50;
    lpf.setPointLabelFormatter(pointLabelFormatter);

    plot.addSeries(openVals, lpf);

    LineAndPointFormatter lpf1 = new LineAndPointFormatter(null, null, null, null);
    PointLabelFormatter pointLabelFormatter1=new PointLabelFormatter();

    //set the vertical offset
    pointLabelFormatter1.vOffset=40;
    lpf1.setPointLabelFormatter(pointLabelFormatter1);

    plot.addSeries(closeVals,lpf1);
    CandlestickFormatter formatter = new CandlestickFormatter();

    formatter.setBodyStyle(CandlestickFormatter.BodyStyle.Square);
    formatter.setLowerCapWidth(50);
    // add the candlestick series data to the plot:
    CandlestickMaker.make(plot, formatter,
            openVals, closeVals, highVals, lowVals);
Gurpreet Kaur
  • 434
  • 1
  • 4
  • 16
  • Could you post a screenshot of what you're seeing? Also would be helpful to see more of the code, particularly the CandlestickFormatter, etc. stuff. – Nick May 07 '16 at 22:53
  • 1
    Hi Nick. sorry for the less explaination. i found the solution by exploring the PointLabelFormatter class. we can set vertical and horizontal offsets for the open/close values. edited the post accordingly. – Gurpreet Kaur May 08 '16 at 05:43
  • Nice! One thing you might consider is tweaking it to use dp instead of pixels, to maintain consistency across devices: formatter.vOffset = PixelUtils.dpToPix(40); – Nick May 08 '16 at 15:57
  • thanks i will consider this :) – Gurpreet Kaur May 11 '16 at 11:11
  • hi nick.. can we change the color of the candlesticks based on custom conditions like right now we can set the color for either fallingBody or risingBody. – Gurpreet Kaur May 12 '16 at 18:06
  • for the moment you might need to extend CandlestickRenderer. or you can wait for the upcoming 1.0 release of Androidplot, which will have a more full featured implementation. – Nick May 13 '16 at 00:29
  • i tried extending the CandlestickRenderer. can you just guide me where can i put my condition. class myRenderer extends CandlestickRenderer{ public myRenderer(XYPlot plot) { super(plot); } @Override public Formatter getFormatter(Series series) { return super.getFormatter(series); } } – Gurpreet Kaur May 13 '16 at 02:33
  • Most straightforward approach would probably be to override drawValue(...), do your check and then adjust the passed in Formatter instance with the color(s) you want to use and then call back to super.drawValue(...). – Nick May 13 '16 at 02:44
  • thanks it worked :) can we change the text color of points also in the same way i.e on custom condition..?? – Gurpreet Kaur May 13 '16 at 09:49

0 Answers0