Android GraphView y 轴未正确递增
Android GraphView y-axis not incrementing correctly
我目前正在开发一个简单的 Android 应用程序,它使用 GraphView
库来创建 BarGraphSeries
,我在绘制数据时注意到一个奇怪的事件.
我正在返回存储在我的本地 SQLite
数据库中的数据计数,每当我将这些值传递给图形 y 轴时,y 轴递增 0.5,但如果我很难编码值(为了测试)y 轴递增 1(所需功能)。
给我带来问题的代码:
// This is how I've declared my variables... I will then go onto call my db
// and populate each variable with a column count.
private static int GREAT_COUNT = 0;
private static int GOOD_COUNT = 0;
private static int MEH_COUNT = 0;
private static int FUGLY_COUNT = 0;
private static int AWFUL_COUNT = 0;
GraphView graph = findViewById(R.id.graph);
BarGraphSeries<DataPoint> series = new BarGraphSeries<>(new DataPoint[] {
new DataPoint(0, GREAT_COUNT),
new DataPoint(1, GOOD_COUNT),
new DataPoint(2, MEH_COUNT),
new DataPoint(3, FUGLY_COUNT),
new DataPoint(4, AWFUL_COUNT)
});
通过将变量传递给 DataPoint 生成的图表:
硬编码值(图表工作正常):
GraphView graph = findViewById(R.id.graph);
BarGraphSeries<DataPoint> series = new BarGraphSeries<>(new DataPoint[] {
new DataPoint(0, 2),
new DataPoint(1, 3),
new DataPoint(2, 7),
new DataPoint(3, 10),
new DataPoint(4, 11)
});
从硬编码值生成的图表:
我是 Android
开发的新手,我一直这样做是为了帮助朋友完成一项任务。我在 int
变量的声明中做错了什么吗,这就是为什么它会导致 y 轴增加 0.5,而硬编码值似乎会像我预期的那样增加整数。
网格线的 y 值是根据 Y 轴的最小值和最大值自动生成的,您绘制的值是 int
并不重要。你的 Y 轴从 2 开始到 4 结束,有四个 "sections"。所以线设置为 2.5、3.0 和 3.5。
- 您可以使用setMinY(0)设置零作为Y轴的起点,然后您将在1、2和3上有网格线。
- 您可以使用 setNumVerticalLabels(1) 只有一条网格线,在您的情况下它会在 3 上。但请注意,您的最大 Y 值是 5 ,那么网格线将位于 3.5
也许有一种方法只允许在整数值上设置网格线,但我没有找到。
我目前正在开发一个简单的 Android 应用程序,它使用 GraphView
库来创建 BarGraphSeries
,我在绘制数据时注意到一个奇怪的事件.
我正在返回存储在我的本地 SQLite
数据库中的数据计数,每当我将这些值传递给图形 y 轴时,y 轴递增 0.5,但如果我很难编码值(为了测试)y 轴递增 1(所需功能)。
给我带来问题的代码:
// This is how I've declared my variables... I will then go onto call my db
// and populate each variable with a column count.
private static int GREAT_COUNT = 0;
private static int GOOD_COUNT = 0;
private static int MEH_COUNT = 0;
private static int FUGLY_COUNT = 0;
private static int AWFUL_COUNT = 0;
GraphView graph = findViewById(R.id.graph);
BarGraphSeries<DataPoint> series = new BarGraphSeries<>(new DataPoint[] {
new DataPoint(0, GREAT_COUNT),
new DataPoint(1, GOOD_COUNT),
new DataPoint(2, MEH_COUNT),
new DataPoint(3, FUGLY_COUNT),
new DataPoint(4, AWFUL_COUNT)
});
通过将变量传递给 DataPoint 生成的图表:
硬编码值(图表工作正常):
GraphView graph = findViewById(R.id.graph);
BarGraphSeries<DataPoint> series = new BarGraphSeries<>(new DataPoint[] {
new DataPoint(0, 2),
new DataPoint(1, 3),
new DataPoint(2, 7),
new DataPoint(3, 10),
new DataPoint(4, 11)
});
从硬编码值生成的图表:
我是 Android
开发的新手,我一直这样做是为了帮助朋友完成一项任务。我在 int
变量的声明中做错了什么吗,这就是为什么它会导致 y 轴增加 0.5,而硬编码值似乎会像我预期的那样增加整数。
网格线的 y 值是根据 Y 轴的最小值和最大值自动生成的,您绘制的值是 int
并不重要。你的 Y 轴从 2 开始到 4 结束,有四个 "sections"。所以线设置为 2.5、3.0 和 3.5。
- 您可以使用setMinY(0)设置零作为Y轴的起点,然后您将在1、2和3上有网格线。
- 您可以使用 setNumVerticalLabels(1) 只有一条网格线,在您的情况下它会在 3 上。但请注意,您的最大 Y 值是 5 ,那么网格线将位于 3.5
也许有一种方法只允许在整数值上设置网格线,但我没有找到。