Change distance between Axis Title and Axis in Android TeeChart

153 views Asked by At

I've tried to change the distance between axis title and axis in Android TeeChart. I played a little bit around with

tChart.getAxes().getLeft().getTitle().setCustomSize();
tChart.getAxes().getBottom().getTitle().setCustomSize();
tChart.getAxes().getLeft().getLabels().setCustomSize();
tChart.getAxes().getBottom().getLabels().setCustomSize();

On the left Axis it works great, but the buttom Axis Title stays in the same Position. Anyone knows a solution?

Thanks.

1

There are 1 answers

1
Yeray On BEST ANSWER

I'm afraid there isn't an single property you can set to add extra space between the axis title and the axis.
The easier way I can think to achieve it is by adding some margin to the chart and draw the axis titles manually on the canvas. Ie:

    Bar bar1 = new Bar(tChart1.getChart());
    bar1.fillSampleValues();

    tChart1.addChartPaintListener(new ChartPaintAdapter() {

        @Override
        public void chartPainted(ChartDrawEvent e) {

            String leftText = "Left Axis Title";
            String bottomText = "Bottom Axis Title";

            int YMid = tChart1.getChart().getChartRect().y + (tChart1.getChart().getChartRect().height / 2);
            int XMid = tChart1.getChart().getChartRect().x + (tChart1.getChart().getChartRect().width / 2);

            tChart1.getGraphics3D().setFont(tChart1.getAxes().getLeft().getTitle().getFont());
            int leftHeight = tChart1.getGraphics3D().textWidth(leftText);
            tChart1.getGraphics3D().rotateLabel(10, YMid + (leftHeight / 2), leftText, 90);

            tChart1.getGraphics3D().setFont(tChart1.getAxes().getBottom().getTitle().getFont());
            int bottomWidth = tChart1.getGraphics3D().textWidth(bottomText);
            tChart1.getGraphics3D().textOut(XMid - (bottomWidth / 2), tChart1.getHeight() - 20, bottomText);
        }
    });

    tChart1.getPanel().setMarginLeft(10);
    tChart1.getPanel().setMarginBottom(10);

Then, you can easily add more margin or move the titles.