0

I'm trying to add axis breaks to my candlesticks chart in android. To add or not to add axis breaks is determined by the underlying data.

On the first picture you can see a normal chart state without axis breaks. Please mention the annotation in the top left corner: The chart without axis breaks

On the second picture you can see the chart with axis breaks. As you can see from the picture, there're some issues:

  1. Halves of the candles are hidden behind the axis break's lines. How can I prevent this overlapping?

  2. Note the position of the annotation: it's shown at the incorrect position and with the strange angle!

  3. Also please mention the 3rd axis break, it's shown incorrectly, too.

enter image description here

Could anyone can suggest how to solve described issues?

4
  • Is this using TeeChart Java for Android or TeeChart .NET for Xamarin.Android?
    – Yeray
    Commented Jan 7, 2015 at 10:50
  • @Yeray TeeChart for Android
    – Dennis
    Commented Jan 7, 2015 at 11:01
  • Java or .NET? This is still not clear
    – Yeray
    Commented Jan 7, 2015 at 12:00
  • Sorry for the delay, I'll reply you asap
    – Yeray
    Commented Jan 8, 2015 at 12:25

1 Answer 1

1
  1. Halves of the candles are hidden behind the axis break's lines. How can I prevent this overlapping?

You can add some margin to the axis break StartValue and EndValue.

  1. Note the position of the annotation: it's shown at the incorrect position and with the strange angle!

I'm not able to reproduce this point with the example code below.
Could you please improve your question adding a simple example project we can run as-is to reproduce the problem here?

  1. Also please mention the 3rd axis break, it's shown incorrectly, too.

I can see an extra axis break being drawn similar to the one in your image, oblique and in the middle of the chart. However, I can only reproduce this problem with the evaluation version, not with the registered version (ID1078).
I assume it has something to do with the "EVALUATION VERSION" oblique watermark we are drawing in the middle of the chart.

Here is the code I used:

    tChart1.getAspect().setView3D(false);
    tChart1.getLegend().setVisible(false);

    Candle candle1 = new Candle(tChart1.getChart());

    candle1.fillSampleValues(80);

    DateTime dt = DateTime.getNow();
    for (int i = 0; i < candle1.getCount(); i++) {
        candle1.getXValues().setValue(i, dt.toDouble());
        dt.add(Calendar.MINUTE, 1);            
    }

    //tChart1.getAxes().getBottom().setIncrement(DateTimeStep.FIVEMINUTES);
    tChart1.getAxes().getBottom().getLabels().setDateTimeFormat("hh:mm");

    AxisBreaksTool axisBreaksTool1 = new AxisBreaksTool(tChart1.getAxes().getBottom());

    for (int i=0; i<3; i++) {
        AxisBreak axisBreak1 = new AxisBreak(axisBreaksTool1);
        axisBreak1.setStartValue(candle1.getXValues().getValue(10*(i+1))-0.6);
        axisBreak1.setEndValue(candle1.getXValues().getValue(10*(i+1)+5)+0.6);
        axisBreak1.setStyle(AxisBreakStyle.LINE);
        axisBreaksTool1.getBreaks().add(axisBreak1);
    }

    Annotation annotation1 = new Annotation(tChart1.getChart());
    annotation1.setText("My Text");
    annotation1.setLeft(10);
    annotation1.setTop(10);

There seems to be a conflict with the Annotation tool and the AxisBreaksTool: as soon as I add an axis break, the annotation disappears (ID1077).


EDIT:

If you want your axis Breaks StartValue and EndValue to depend on the CandleWidth, you could calculate the size of the candle width in axis units, but you need the chart to be drawn to do this.
Here is how you could use the ChartPaintListener to calculate the CandleWidth in the bottom axis units and use it as extra margin for the AxisBreaks:

    tChart1.addChartPaintListener(new ChartPaintAdapter() {

        @Override
        public void chartPainted(ChartDrawEvent e) {
            Candle candle1 = (Candle)tChart1.getSeries(0);
            double onePxWidth = tChart1.getAxes().getBottom().calcPosPoint(1) - tChart1.getAxes().getBottom().calcPosPoint(0); 
            double tmpWidthLeft = onePxWidth*(candle1.getCandleWidth()/2 + 4);
            double tmpWidthRight = onePxWidth*(candle1.getCandleWidth()/2 + 3);

            AxisBreaksTool axisBreaksTool1 = (AxisBreaksTool)tChart1.getTools().getTool(0);
            for (int i=0; i<axisBreaksTool1.getBreaks().size(); i++) {
                AxisBreak axisBreak1 = axisBreaksTool1.getBreaks().get(i);
                axisBreak1.setStartValue(candle1.getXValues().getValue(10*(i+1))+tmpWidthLeft);
                axisBreak1.setEndValue(candle1.getXValues().getValue(10*(i+1)+5)-tmpWidthRight);
            }
        }
    }); 
4
  • thank you for the reply! I've subscribed to bugs in Steema's bugzilla.
    – Dennis
    Commented Jan 8, 2015 at 18:34
  • could you please explain me how to guess about margin values in data terms? In my case, depending on the data scale, the distance between two bars can be from 1 minute to 31 days. How should I convert DateTime values into pixels? You know, we specify candle's width in pixels, not in data terms. So I can't guess which margin to add for my axis break to achieve, for example, 3px, which in my case is the half width of the candle...
    – Dennis
    Commented Jan 8, 2015 at 18:40
  • I've made an experiment and see that distance between 2 bars in double equals number of milliseconds between the bars' values.
    – Dennis
    Commented Jan 8, 2015 at 18:51
  • I've edited my answer adding an example using ChartPaintListener
    – Yeray
    Commented Jan 12, 2015 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.