为什么 GraphView 不能绘制这些点?如果第二个点的 x 值小于第一个点
Why can not GraphView plot these points? If the second point has a x value less than first point
如果第二个点的 x 值小于第一个点,android 的 GraphView 无法绘制这些点。
<com.jjoe64.graphview.GraphView
android:id="@+id/GPH_graph"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/STL_Graph"/>
DataPoint[] DP_Array = new DataPoint[]{new DataPoint( 0, 0), new DataPoint(-10,10)};
LineH1 = new LineGraphSeries<>(DP_Array);
LineH1.setColor(getResources().getColor(R.color.black));
GPH_graph.addSeries(LineH1);
我想把这些点画成这张图
我用下面的代码解决了这个问题:
List<LineGraphSeries<DataPoint>> Series;
Series = SetSeries(DP_Array);
for (int i = 0; i < Series.size(); i++)
{
GPH_graph.addSeries(Series.get(i));
}
List<LineGraphSeries<DataPoint>> SetSeries(DataPoint[] AllData)
{
List<LineGraphSeries<DataPoint>> LineGraphSeriesList = new ArrayList<> ();
DataPoint[] DP;
boolean bol_Forward = true;
int NumForward = 0;
int NumBackward = 0;
for(int i = 1;i < AllData.length;i++)
{
if(AllData[i].getX() >= AllData[i-1].getX())
{
NumForward++;
bol_Forward = true;
}
else
{
NumBackward++;
bol_Forward = false;
}
if(NumBackward>0 & NumForward>0)
{
if(bol_Forward == false)
{
DP = new DataPoint[NumForward + 1];
for (int A = 0;A < NumForward + 1;A++)
{
DP[NumForward - A] = new DataPoint(AllData[i - 1 - A].getX(),AllData[i - 1 - A].getY());
}
LineGraphSeriesList.add(new LineGraphSeries<>(DP));
NumForward = 0;
}
else
{
DP = new DataPoint[NumBackward + 1];
for (int A = 0;A < NumBackward + 1;A++)
{
DP[A] = new DataPoint(AllData[i - 1 - A].getX(),AllData[i - 1 - A].getY());
}
LineGraphSeriesList.add(new LineGraphSeries<>(DP));
NumBackward = 0;
}
Num++;
}
}
return LineGraphSeriesList;
}
如果第二个点的 x 值小于第一个点,android 的 GraphView 无法绘制这些点。
<com.jjoe64.graphview.GraphView
android:id="@+id/GPH_graph"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/STL_Graph"/>
DataPoint[] DP_Array = new DataPoint[]{new DataPoint( 0, 0), new DataPoint(-10,10)};
LineH1 = new LineGraphSeries<>(DP_Array);
LineH1.setColor(getResources().getColor(R.color.black));
GPH_graph.addSeries(LineH1);
我想把这些点画成这张图
我用下面的代码解决了这个问题:
List<LineGraphSeries<DataPoint>> Series;
Series = SetSeries(DP_Array);
for (int i = 0; i < Series.size(); i++)
{
GPH_graph.addSeries(Series.get(i));
}
List<LineGraphSeries<DataPoint>> SetSeries(DataPoint[] AllData)
{
List<LineGraphSeries<DataPoint>> LineGraphSeriesList = new ArrayList<> ();
DataPoint[] DP;
boolean bol_Forward = true;
int NumForward = 0;
int NumBackward = 0;
for(int i = 1;i < AllData.length;i++)
{
if(AllData[i].getX() >= AllData[i-1].getX())
{
NumForward++;
bol_Forward = true;
}
else
{
NumBackward++;
bol_Forward = false;
}
if(NumBackward>0 & NumForward>0)
{
if(bol_Forward == false)
{
DP = new DataPoint[NumForward + 1];
for (int A = 0;A < NumForward + 1;A++)
{
DP[NumForward - A] = new DataPoint(AllData[i - 1 - A].getX(),AllData[i - 1 - A].getY());
}
LineGraphSeriesList.add(new LineGraphSeries<>(DP));
NumForward = 0;
}
else
{
DP = new DataPoint[NumBackward + 1];
for (int A = 0;A < NumBackward + 1;A++)
{
DP[A] = new DataPoint(AllData[i - 1 - A].getX(),AllData[i - 1 - A].getY());
}
LineGraphSeriesList.add(new LineGraphSeries<>(DP));
NumBackward = 0;
}
Num++;
}
}
return LineGraphSeriesList;
}