首页 > 解决方案 > Android MPAndroidChart xasis 值显示大于 1

问题描述

我正在使用 android java MPAndroidChart 库。从照片中可以看出,x 轴的值显示不止一个。我只想在星期二显示一次。我该怎么做 图表的图像

标签: javaandroidplotgraphmpandroidchart

解决方案


您可以强制设置标签计数。这将导致仅在您的轴上生成一个标签。例如:

xAxis.setLabelCount(1, true)

从文档中:

 /**
     * sets the number of label entries for the y-axis max = 25, min = 2, default: 6, be aware
     * that this number is not
     * fixed (if force == false) and can only be approximated.
     *
     * @param count the number of y-axis labels that should be displayed
     * @param force if enabled, the set label count will be forced, meaning that the exact
     *              specified count of labels will
     *              be drawn and evenly distributed alongside the axis - this might cause labels
     *              to have uneven values
     */
    public void setLabelCount(int count, boolean force) {

        setLabelCount(count);
        mForceLabels = force;
    }

您可以尝试的另一件事是更多地使用粒度。像这样:

axisLeft.granularity = 3F

从文档:

 /**
     * Set a minimum interval for the axis when zooming in. The axis is not allowed to go below
     * that limit. This can be used to avoid label duplicating when zooming in.
     *
     * @param granularity
     */
    public void setGranularity(float granularity) {
        mGranularity = granularity;
        // set this to true if it was disabled, as it makes no sense to call this method with granularity disabled
        mGranularityEnabled = true;
    }

推荐阅读