【问题标题】:Change distance between Axis Title and Axis in Android TeeChart在 Android TeeChart 中更改 Axis Title 和 Axis 之间的距离
【发布时间】:2015-06-24 13:15:52
【问题描述】:

我尝试在 Android TeeChart 中更改轴标题和轴之间的距离。我玩了一点

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

在左侧轴上效果很好,但底部轴标题保持在相同的位置。有谁知道解决办法吗?

谢谢。

【问题讨论】:

    标签: java android teechart


    【解决方案1】:

    恐怕没有一个属性可以设置为在轴标题和轴之间添加额外的空间。
    我认为实现它的更简单方法是在图表中添加一些边距并在画布上手动绘制轴标题。即:

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

    然后,您可以轻松地添加更多边距或移动标题。

    【讨论】:

    • 再次感谢 Yeray。抱歉,我还不能投票给你的答案,我需要更多的声誉。我认为有一种更简单的方法,因为轴标题总是与轴标签重叠。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-27
    相关资源
    最近更新 更多