Change distance between Axis Title and Axis in Android TeeChart

牧云@^-^@ 提交于 2020-01-17 03:49:10

问题


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:


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.



来源:https://stackoverflow.com/questions/31027660/change-distance-between-axis-title-and-axis-in-android-teechart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!