Android MPAndroid图表 x 轴值显示大于 1

Android MPAndroidChart xasis values showing more than 1

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

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

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

我找到了解决办法 假设您的列表名称是 myArray,答案是

barChart.getXAxis().setLabelCount(myArray.size());