Dennis
Dennis

Reputation: 108

Using AxisBreaks with Candles in TeeChart Android

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?

Upvotes: 0

Views: 153

Answers (1)

Yeray
Yeray

Reputation: 5039

  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);
            }
        }
    }); 

Upvotes: 1

Related Questions