我使用的是多Y轴图形的绘制点
我有1)X轴2)Y1轴3)Y2轴
一)最初我用来绘制5系列Y1轴(高度)和同为5系列Y2线(重量)的行轴两者相对于X轴,,,,不存在问题这里,,,这些一系列的线为标准线,用于每个计算,,
b)现在如果用户输入了两个他的身高和体重我得出两个额外的线路,所以有12个系列线路,包括标准线,,
C)Supppose如果用户输入单独身高,但不重应用程序的力量关闭,,说的数据集和渲染器不能为空,应该有一系列的相同数量
code如下,,
公共GraphicalView执行(上下文的背景下,用户名字符串,
字符串HeightRe presentation,弦乐WeightRe presentation,
ArrayList的<双> mHeightValueCms,
ArrayList的<双> mWeightValueKg,
ArrayList的<双> mHeightInCmsMonthDate,
ArrayList的<双> mWeightInKgMonthDate,
ArrayList的<双> mHeightMonth97,ArrayList的<双> mHeightMonth75,
ArrayList的<双> mHeightMonth50,ArrayList的<双> mHeightMonth25,
ArrayList的<双> mHeightMonth3,ArrayList的<双> mWeightMonth97,
ArrayList的<双> mWeightMonth75,ArrayList的<双> mWeightMonth50,
ArrayList的<双> mWeightMonth25,ArrayList的<双> mWeightMonth3){
XYMultipleSeriesRenderer渲染= NULL;
串[]标题=新串[] {97%,75%,50%,25%,3%};
名单<加倍[]> X =新的ArrayList<加倍[]>();
名单<加倍[]> X1 =新的ArrayList<加倍[]>();
的for(int i = 0; I< titles.length;我++){
x.add(新的双[] {0,3,6,9,12,15,18,21,24,27,30,33,36});
}
名单<加倍[]>值=新的ArrayList<加倍[]>();
values.add(新的双[] {mHeightMonth97.get(0),mHeightMonth97.get(1)
mHeightMonth97.get(2),mHeightMonth97.get(3),
mHeightMonth97.get(4),mHeightMonth97.get(5),
mHeightMonth97.get(6),mHeightMonth97.get(7),
mHeightMonth97.get(8),mHeightMonth97.get(9),
mHeightMonth97.get(10),mHeightMonth97.get(11),
mHeightMonth97.get(12)});
values.add(新的双[] {mHeightMonth75.get(0),mHeightMonth75.get(1)
mHeightMonth75.get(2),mHeightMonth75.get(3),
mHeightMonth75.get(4),mHeightMonth75.get(5),
mHeightMonth75.get(6),mHeightMonth75.get(7),
mHeightMonth75.get(8),mHeightMonth75.get(9),
mHeightMonth75.get(10),mHeightMonth75.get(11),
mHeightMonth75.get(12)});
values.add(新的双[] {mHeightMonth50.get(0),mHeightMonth50.get(1)
mHeightMonth50.get(2),mHeightMonth50.get(3),
mHeightMonth50.get(4),mHeightMonth50.get(5),
mHeightMonth50.get(6),mHeightMonth50.get(7),
mHeightMonth50.get(8),mHeightMonth50.get(9),
mHeightMonth50.get(10),mHeightMonth50.get(11),
mHeightMonth50.get(12)});
values.add(新的双[] {mHeightMonth25.get(0),mHeightMonth25.get(1)
mHeightMonth25.get(2),mHeightMonth25.get(3),
mHeightMonth25.get(4),mHeightMonth25.get(5),
mHeightMonth25.get(6),mHeightMonth25.get(7),
mHeightMonth25.get(8),mHeightMonth25.get(9),
mHeightMonth25.get(10),mHeightMonth25.get(11),
mHeightMonth25.get(12)});
values.add(新的双[] {mHeightMonth3.get(0),mHeightMonth3.get(1)
mHeightMonth3.get(2),mHeightMonth3.get(3),
mHeightMonth3.get(4),mHeightMonth3.get(5),
mHeightMonth3.get(6),mHeightMonth3.get(7),
mHeightMonth3.get(8),mHeightMonth3.get(9),
mHeightMonth3.get(10),mHeightMonth3.get(11),
mHeightMonth3.get(12)});
INT []颜色= NULL;
PointStyle []风格= NULL;
如果((mWeightInKgMonthDate.isEmpty()及!&安培; mHeightInCmsMonthDate.isEmpty())){
渲染器=新XYMultipleSeriesRenderer(12);
颜色=新INT [] {
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
Color.GREEN,
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
Color.RED};
风格=新PointStyle [] {PointStyle.POINT,PointStyle.POINT,
PointStyle.POINT,PointStyle.POINT,PointStyle.POINT,
PointStyle.TRIANGLE,PointStyle.POINT,PointStyle.POINT,
PointStyle.POINT,PointStyle.POINT,PointStyle.POINT,
PointStyle.TRIANGLE};
} 其他
如果(mWeightInKgMonthDate.isEmpty()及!&安培; mHeightInCmsMonthDate.isEmpty()){
渲染=新XYMultipleSeriesRenderer(11);
颜色=新INT [] {
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
Color.RED};
风格=新PointStyle [] {PointStyle.POINT,PointStyle.POINT,
PointStyle.POINT,PointStyle.POINT,PointStyle.POINT,
PointStyle.POINT,PointStyle.POINT,PointStyle.POINT,
PointStyle.POINT,PointStyle.POINT,PointStyle.TRIANGLE};
} 其他
如果(mWeightInKgMonthDate.isEmpty()&安培;&安培;!mHeightInCmsMonthDate.isEmpty()){
渲染=新XYMultipleSeriesRenderer(11);
颜色=新INT [] {
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
Color.GREEN,
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
。context.getResources()的getColor(R.color.LightRed)};
风格=新PointStyle [] {PointStyle.POINT,PointStyle.POINT,
PointStyle.POINT,PointStyle.POINT,PointStyle.POINT,
PointStyle.TRIANGLE,PointStyle.POINT,PointStyle.POINT,
PointStyle.POINT,PointStyle.POINT,PointStyle.POINT};
} 其他
如果(mWeightInKgMonthDate.isEmpty()&安培;&安培; mHeightInCmsMonthDate.isEmpty()){
渲染=新XYMultipleSeriesRenderer(10);
颜色=新INT [] {
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightGreen)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
context.getResources()的getColor(R.color.LightRed)
。context.getResources()的getColor(R.color.LightRed)};
风格=新PointStyle [] {PointStyle.POINT,PointStyle.POINT,
PointStyle.POINT,PointStyle.POINT,PointStyle.POINT,
PointStyle.POINT,PointStyle.POINT,PointStyle.POINT,
PointStyle.POINT,PointStyle.POINT};
}
setRenderer(渲染,颜色,款式);
INT长度= renderer.getSeriesRendererCount();
的for(int i = 0; I<长度;我++){
XYSeriesRenderer R =((XYSeriesRenderer)渲染器
.getSeriesRendererAt(ⅰ));
r.setFillPoints(真正的);
r.setLineWidth(3F);
// / -----
r.setShowLegendItem(假);
}
如果(HeightRe presentation.equals(HeightInCms)及&安培; WeightRe presentation.equals(WeightInKg)){
setChartSettings(渲染器,成长图表+用户名,月,
在(CMS)高度0,36,45,180,Color.LTGRAY,Color.LTGRAY);
renderer.setYTitle(在重量(kg),1);
}否则,如果(HeightRe presentation.equals(HeightInFt)及和放大器; WeightRe presentation.equals(WeightInKg)){
setChartSettings(渲染器,成长图表+用户名,月,
,在(英尺)高度0,36,0,8,Color.LTGRAY,Color.LTGRAY);
renderer.setYTitle(在重量(kg),1);
}否则,如果(HeightRe presentation.equals(HeightInCms)及和放大器; WeightRe presentation.equals(WeightInLbs)){
setChartSettings(渲染器,成长图表+用户名,月,
在(CMS)高度0,36,45,180,Color.LTGRAY,Color.LTGRAY);
renderer.setYTitle(重量中(磅),1);
}否则,如果(HeightRe presentation.equals(HeightInFt)及和放大器; WeightRe presentation.equals(WeightInLbs)){
setChartSettings(渲染器,成长图表+用户名,月,
,在(英尺)高度0,36,0,8,Color.LTGRAY,Color.LTGRAY);
renderer.setYTitle(重量中(磅),1);
}
renderer.setXLabels(12);
renderer.setYLabels(10);
renderer.setShowGrid(真正的);
renderer.setApplyBackgroundColor(真正的);
renderer.setBackgroundColor(Color.BLACK);
// renderer.setPointSize(3);
// renderer.setGridColor(Color.WHITE);
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setZoomButtonsVisible(真正的);
// renderer.setPanLimits(新的双[] {-50,50,0,250});
// renderer.setZoomLimits(新的双[] {-50,50,0,250});
renderer.setZoomRate(1.05f);
renderer.setLabelsColor(Color.WHITE);
renderer.setXLabelsColor(Color.WHITE);
renderer.setYLabelsColor(0,颜色[0]);
renderer.setYLabelsColor(1,Color.RED);
renderer.setYAxisAlign(Align.RIGHT,1);
renderer.setYLabelsAlign(Align.LEFT,1);
XYMultipleSeriesDataset数据集= NULL;
如果(mHeightInCmsMonthDate.isEmpty()及!&安培;!mHeightValueCms.isEmpty()){
XYSeries SeperateY1 =新XYSeries();
的for(int i = 0; I< mHeightInCmsMonthDate.size();我++){
SeperateY1.add(mHeightInCmsMonthDate.get(ⅰ),
mHeightValueCms.get(ⅰ));
}
数据集= buildDataset(标题,X值);
dataset.addSeries(SeperateY1);
} 其他 {
数据集= buildDataset(标题,X值);
}
XYSeries seriesMin1,seriesMin2,seriesMin3,seriesMin4,seriesMin5,seriesMin6,seriesMin7,seriesMin8,seriesMin9,seriesMin10,seriesMin11,seriesMin12;
如果(!mHeightInCmsMonthDate.isEmpty()){
seriesMin1 = dataset.getSeriesAt(0);
seriesMin2 = dataset.getSeriesAt(1);
seriesMin3 = dataset.getSeriesAt(2);
seriesMin4 = dataset.getSeriesAt(3);
seriesMin5 = dataset.getSeriesAt(4);
seriesMin6 = dataset.getSeriesAt(5);
seriesMin1.addAnnotation(3%,37,
mHeightMonth3.get(mHeightMonth3.size() - 1));
seriesMin2.addAnnotation(25%,37,
mHeightMonth25.get(mHeightMonth25.size() - 1));
seriesMin3.addAnnotation(50%,37,
mHeightMonth50.get(mHeightMonth50.size() - 1));
seriesMin4.addAnnotation(75%,37,
mHeightMonth75.get(mHeightMonth75.size() - 1));
seriesMin5.addAnnotation(97%,37,
mHeightMonth97.get(mHeightMonth97.size() - 1));
的for(int i = 0; I< mHeightInCmsMonthDate.size();我++){
seriesMin6.addAnnotation((+ mHeightInCmsMonthDate.get㈠
+,+ mHeightValueCms.get(ⅰ)+),
mHeightInCmsMonthDate.get(i)中,mHeightValueCms.get(ⅰ));
}
} 其他 {
seriesMin1 = dataset.getSeriesAt(0);
seriesMin2 = dataset.getSeriesAt(1);
seriesMin3 = dataset.getSeriesAt(2);
seriesMin4 = dataset.getSeriesAt(3);
seriesMin5 = dataset.getSeriesAt(4);
seriesMin1.addAnnotation(3%,37,
mHeightMonth3.get(mHeightMonth3.size() - 1));
seriesMin2.addAnnotation(25%,37,
mHeightMonth25.get(mHeightMonth25.size() - 1));
seriesMin3.addAnnotation(50%,37,
mHeightMonth50.get(mHeightMonth50.size() - 1));
seriesMin4.addAnnotation(75%,37,
mHeightMonth75.get(mHeightMonth75.size() - 1));
seriesMin5.addAnnotation(97%,37,
mHeightMonth97.get(mHeightMonth97.size() - 1));
}
values.clear();
名单<加倍[]>值1 =新的ArrayList<加倍[]>();
名单<加倍[]> values2 =新的ArrayList<加倍[]>();
名单<加倍[]>値=新的ArrayList<加倍[]>();
名单<加倍[]> values4 =新的ArrayList<加倍[]>();
名单<加倍[]> values5 =新的ArrayList<加倍[]>();
名单<加倍[]> values6 =新的ArrayList<加倍[]>();
values1.add(新的双[] {mWeightMonth97.get(0)
mWeightMonth97.get(1),mWeightMonth97.get(2),
mWeightMonth97.get(3),mWeightMonth97.get(4),
mWeightMonth97.get(5),mWeightMonth97.get(6),
mWeightMonth97.get(7),mWeightMonth97.get(8),
mWeightMonth97.get(9),mWeightMonth97.get(10),
mWeightMonth97.get(11),mWeightMonth97.get(12)});
addXYSeries(数据集,新的String [] {97%}中,x,值1,1);
values2.add(新的双[] {mWeightMonth75.get(0)
mWeightMonth75.get(1),mWeightMonth75.get(2),
mWeightMonth75.get(3),mWeightMonth75.get(4),
mWeightMonth75.get(5),mWeightMonth75.get(6),
mWeightMonth75.get(7),mWeightMonth75.get(8),
mWeightMonth75.get(9),mWeightMonth75.get(10),
mWeightMonth75.get(11),mWeightMonth75.get(12)});
addXYSeries(数据集,新的String [] {75%}中,x,values2,1);
values3.add(新的双[] {mWeightMonth50.get(0)
mWeightMonth50.get(1),mWeightMonth50.get(2),
mWeightMonth50.get(3),mWeightMonth50.get(4),
mWeightMonth50.get(5),mWeightMonth50.get(6),
mWeightMonth50.get(7),mWeightMonth50.get(8),
mWeightMonth50.get(9),mWeightMonth50.get(10),
mWeightMonth50.get(11),mWeightMonth50.get(12)});
addXYSeries(数据集,新的String [] {50%}中,x,値3,1);
values4.add(新的双[] {mWeightMonth25.get(0)
mWeightMonth25.get(1),mWeightMonth25.get(2),
mWeightMonth25.get(3),mWeightMonth25.get(4),
mWeightMonth25.get(5),mWeightMonth25.get(6),
mWeightMonth25.get(7),mWeightMonth25.get(8),
mWeightMonth25.get(9),mWeightMonth25.get(10),
mWeightMonth25.get(11),mWeightMonth25.get(12)});
addXYSeries(数据集,新的String [] {25%},X,values4,1);
values5.add(新的双[] {mWeightMonth3.get(0),mWeightMonth3.get(1)
mWeightMonth3.get(2),mWeightMonth3.get(3),
mWeightMonth3.get(4),mWeightMonth3.get(5),
mWeightMonth3.get(6),mWeightMonth3.get(7),
mWeightMonth3.get(8),mWeightMonth3.get(9),
mWeightMonth3.get(10),mWeightMonth3.get(11),
mWeightMonth3.get(12)});
addXYSeries(数据集,新的String [] {3%(重量)}中,x,values5,1);
双[] WeightInKg = NULL;
如果(mWeightValueKg.isEmpty()及!&安培;!mWeightInKgMonthDate.isEmpty()){
WeightInKg =新的双[mWeightValueKg.size()];
的for(int i = 0; I< mWeightValueKg.size();我++){
WeightInKg [I] = mWeightValueKg.get(ⅰ);
}
values6.add(WeightInKg);
双[] DATEVALUE =新的双[mWeightInKgMonthDate.size()];
的for(int i = 0; I< mWeightInKgMonthDate.size();我++){
DATEVALUE [I] = mWeightInKgMonthDate.get(ⅰ);
}
x1.add(DATEVALUE);
addXYSeries(数据集,新的String [] {},X1,values6,1);
}
如果(!mHeightInCmsMonthDate.isEmpty()){
seriesMin7 = dataset.getSeriesAt(6);
seriesMin8 = dataset.getSeriesAt(7);
seriesMin9 = dataset.getSeriesAt(8);
seriesMin10 = dataset.getSeriesAt(9);
seriesMin11 = dataset.getSeriesAt(10);
seriesMin7.addAnnotation(3%,37,
mWeightMonth3.get(mWeightMonth3.size() - 1));
seriesMin8.addAnnotation(25%,37,
mWeightMonth25.get(mWeightMonth25.size() - 1));
seriesMin9.addAnnotation(50%,37,
mWeightMonth50.get(mWeightMonth50.size() - 1));
seriesMin10.addAnnotation(75%,37,
mWeightMonth75.get(mWeightMonth75.size() - 1));
seriesMin11.addAnnotation(97%,37,
mWeightMonth97.get(mWeightMonth97.size() - 1));
如果(!mWeightInKgMonthDate.isEmpty()){
seriesMin12 = dataset.getSeriesAt(11);
的for(int i = 0; I< mWeightInKgMonthDate.size();我++){
seriesMin12.addAnnotation((+ mWeightInKgMonthDate.get㈠
+,+ WeightInKg [I] +),
mWeightInKgMonthDate.get(i)中,WeightInKg [I]);
}
}
} 其他 {
seriesMin6 = dataset.getSeriesAt(5);
seriesMin7 = dataset.getSeriesAt(6);
seriesMin8 = dataset.getSeriesAt(7);
seriesMin9 = dataset.getSeriesAt(8);
seriesMin10 = dataset.getSeriesAt(9);
seriesMin6.addAnnotation(3%,37,
mWeightMonth3.get(mWeightMonth3.size() - 1));
seriesMin7.addAnnotation(25%,37,
mWeightMonth25.get(mWeightMonth25.size() - 1));
seriesMin8.addAnnotation(50%,37,
mWeightMonth50.get(mWeightMonth50.size() - 1));
seriesMin9.addAnnotation(75%,37,
mWeightMonth75.get(mWeightMonth75.size() - 1));
seriesMin10.addAnnotation(97%,37,
mWeightMonth97.get(mWeightMonth97.size() - 1));
如果(!mWeightInKgMonthDate.isEmpty()){
seriesMin11 = dataset.getSeriesAt(10);
的for(int i = 0; I< mWeightInKgMonthDate.size();我++){
seriesMin11.addAnnotation((+ mWeightInKgMonthDate.get㈠
+,+ WeightInKg [I] +),
mWeightInKgMonthDate.get(i)中,WeightInKg [I]);
}
}
}
GraphicalView MVIEW = ChartFactory.getCubeLineChartView(背景下,
数据集,渲染,0.3f);
返回MView的;
}
解决方案
抱歉,这个问题与我上面所使用的逻辑,我已经改变了行
如果(!(mWeightInKgMonthDate.isEmpty()及和放大器; mHeightInCmsMonthDate.isEmpty()))
到
如果(!mWeightInKgMonthDate.isEmpty()及和放大器;!mHeightInCmsMonthDate.isEmpty())
完蛋了。
I'm using Multiple Y axis Graph for plotting points
I have 1)X-axis 2)Y1-axis 3)Y2-axis
a)Initially I used to draw 5 series of lines on Y1 axes(Height) and Same 5 series of lines(Weight) on Y2 axes both with respect to x-axis,,,,No problem exists here,,,these series of lines are standard lines and used for every calculation,,
b)Now If user enters both his height and weight I draw two extra Lines ,so there are 12 series of lines including standard lines,,
c)Supppose if the user enters alone Height but not weight the app force closes,,saying dataset and renderer should not be null and should have same number of series
code follows,,
public GraphicalView execution(Context context, String UserName,
String HeightRepresentation, String WeightRepresentation,
ArrayList<Double> mHeightValueCms,
ArrayList<Double> mWeightValueKg,
ArrayList<Double> mHeightInCmsMonthDate,
ArrayList<Double> mWeightInKgMonthDate,
ArrayList<Double> mHeightMonth97, ArrayList<Double> mHeightMonth75,
ArrayList<Double> mHeightMonth50, ArrayList<Double> mHeightMonth25,
ArrayList<Double> mHeightMonth3, ArrayList<Double> mWeightMonth97,
ArrayList<Double> mWeightMonth75, ArrayList<Double> mWeightMonth50,
ArrayList<Double> mWeightMonth25, ArrayList<Double> mWeightMonth3) {
XYMultipleSeriesRenderer renderer = null;
String[] titles = new String[] { "97%", "75%", "50%", "25%", "3% " };
List<double[]> x = new ArrayList<double[]>();
List<double[]> x1 = new ArrayList<double[]>();
for (int i = 0; i < titles.length; i++) {
x.add(new double[] { 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36 });
}
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] { mHeightMonth97.get(0), mHeightMonth97.get(1),
mHeightMonth97.get(2), mHeightMonth97.get(3),
mHeightMonth97.get(4), mHeightMonth97.get(5),
mHeightMonth97.get(6), mHeightMonth97.get(7),
mHeightMonth97.get(8), mHeightMonth97.get(9),
mHeightMonth97.get(10), mHeightMonth97.get(11),
mHeightMonth97.get(12) });
values.add(new double[] { mHeightMonth75.get(0), mHeightMonth75.get(1),
mHeightMonth75.get(2), mHeightMonth75.get(3),
mHeightMonth75.get(4), mHeightMonth75.get(5),
mHeightMonth75.get(6), mHeightMonth75.get(7),
mHeightMonth75.get(8), mHeightMonth75.get(9),
mHeightMonth75.get(10), mHeightMonth75.get(11),
mHeightMonth75.get(12) });
values.add(new double[] { mHeightMonth50.get(0), mHeightMonth50.get(1),
mHeightMonth50.get(2), mHeightMonth50.get(3),
mHeightMonth50.get(4), mHeightMonth50.get(5),
mHeightMonth50.get(6), mHeightMonth50.get(7),
mHeightMonth50.get(8), mHeightMonth50.get(9),
mHeightMonth50.get(10), mHeightMonth50.get(11),
mHeightMonth50.get(12) });
values.add(new double[] { mHeightMonth25.get(0), mHeightMonth25.get(1),
mHeightMonth25.get(2), mHeightMonth25.get(3),
mHeightMonth25.get(4), mHeightMonth25.get(5),
mHeightMonth25.get(6), mHeightMonth25.get(7),
mHeightMonth25.get(8), mHeightMonth25.get(9),
mHeightMonth25.get(10), mHeightMonth25.get(11),
mHeightMonth25.get(12) });
values.add(new double[] { mHeightMonth3.get(0), mHeightMonth3.get(1),
mHeightMonth3.get(2), mHeightMonth3.get(3),
mHeightMonth3.get(4), mHeightMonth3.get(5),
mHeightMonth3.get(6), mHeightMonth3.get(7),
mHeightMonth3.get(8), mHeightMonth3.get(9),
mHeightMonth3.get(10), mHeightMonth3.get(11),
mHeightMonth3.get(12) });
int[] colors = null;
PointStyle[] styles = null;
if (!(mWeightInKgMonthDate.isEmpty() && mHeightInCmsMonthDate.isEmpty())) {
renderer = new XYMultipleSeriesRenderer(12);
colors = new int[] {
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
Color.GREEN,
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
Color.RED };
styles = new PointStyle[] { PointStyle.POINT, PointStyle.POINT,
PointStyle.POINT, PointStyle.POINT, PointStyle.POINT,
PointStyle.TRIANGLE, PointStyle.POINT, PointStyle.POINT,
PointStyle.POINT, PointStyle.POINT, PointStyle.POINT,
PointStyle.TRIANGLE };
} else
if (!mWeightInKgMonthDate.isEmpty() && mHeightInCmsMonthDate.isEmpty()) {
renderer = new XYMultipleSeriesRenderer(11);
colors = new int[] {
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
Color.RED };
styles = new PointStyle[] { PointStyle.POINT, PointStyle.POINT,
PointStyle.POINT, PointStyle.POINT, PointStyle.POINT,
PointStyle.POINT, PointStyle.POINT, PointStyle.POINT,
PointStyle.POINT, PointStyle.POINT, PointStyle.TRIANGLE };
} else
if (mWeightInKgMonthDate.isEmpty() && !mHeightInCmsMonthDate.isEmpty()) {
renderer = new XYMultipleSeriesRenderer(11);
colors = new int[] {
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
Color.GREEN,
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed) };
styles = new PointStyle[] { PointStyle.POINT, PointStyle.POINT,
PointStyle.POINT, PointStyle.POINT, PointStyle.POINT,
PointStyle.TRIANGLE, PointStyle.POINT, PointStyle.POINT,
PointStyle.POINT, PointStyle.POINT, PointStyle.POINT };
} else
if (mWeightInKgMonthDate.isEmpty() && mHeightInCmsMonthDate.isEmpty()) {
renderer = new XYMultipleSeriesRenderer(10);
colors = new int[] {
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightGreen),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed),
context.getResources().getColor(R.color.LightRed) };
styles = new PointStyle[] { PointStyle.POINT, PointStyle.POINT,
PointStyle.POINT, PointStyle.POINT, PointStyle.POINT,
PointStyle.POINT, PointStyle.POINT, PointStyle.POINT,
PointStyle.POINT, PointStyle.POINT };
}
setRenderer(renderer, colors, styles);
int length = renderer.getSeriesRendererCount();
for (int i = 0; i < length; i++) {
XYSeriesRenderer r = ((XYSeriesRenderer) renderer
.getSeriesRendererAt(i));
r.setFillPoints(true);
r.setLineWidth(3f);
// /-----
r.setShowLegendItem(false);
}
if(HeightRepresentation.equals("HeightInCms") && WeightRepresentation.equals("WeightInKg")){
setChartSettings(renderer, "Growth Chart For " + UserName, "Month",
"Height in (cms)", 0, 36, 45, 180, Color.LTGRAY, Color.LTGRAY);
renderer.setYTitle("Weight in (kg)", 1);
}else if(HeightRepresentation.equals("HeightInFt") && WeightRepresentation.equals("WeightInKg")){
setChartSettings(renderer, "Growth Chart For " + UserName, "Month",
"Height in (ft)", 0, 36, 0, 8, Color.LTGRAY, Color.LTGRAY);
renderer.setYTitle("Weight in (kg)", 1);
}else if(HeightRepresentation.equals("HeightInCms") && WeightRepresentation.equals("WeightInLbs")){
setChartSettings(renderer, "Growth Chart For " + UserName, "Month",
"Height in (cms)", 0, 36, 45, 180, Color.LTGRAY, Color.LTGRAY);
renderer.setYTitle("Weight in (lbs)", 1);
}else if(HeightRepresentation.equals("HeightInFt") && WeightRepresentation.equals("WeightInLbs")){
setChartSettings(renderer, "Growth Chart For " + UserName, "Month",
"Height in (ft)", 0, 36, 0, 8, Color.LTGRAY, Color.LTGRAY);
renderer.setYTitle("Weight in (lbs)", 1);
}
renderer.setXLabels(12);
renderer.setYLabels(10);
renderer.setShowGrid(true);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.BLACK);
// renderer.setPointSize(3);
// renderer.setGridColor(Color.WHITE);
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setZoomButtonsVisible(true);
// renderer.setPanLimits(new double[] { -50, 50, 0, 250 });
// renderer.setZoomLimits(new double[] { -50, 50, 0, 250 });
renderer.setZoomRate(1.05f);
renderer.setLabelsColor(Color.WHITE);
renderer.setXLabelsColor(Color.WHITE);
renderer.setYLabelsColor(0, colors[0]);
renderer.setYLabelsColor(1, Color.RED);
renderer.setYAxisAlign(Align.RIGHT, 1);
renderer.setYLabelsAlign(Align.LEFT, 1);
XYMultipleSeriesDataset dataset = null;
if (!mHeightInCmsMonthDate.isEmpty() && !mHeightValueCms.isEmpty()) {
XYSeries SeperateY1 = new XYSeries("");
for (int i = 0; i < mHeightInCmsMonthDate.size(); i++) {
SeperateY1.add(mHeightInCmsMonthDate.get(i),
mHeightValueCms.get(i));
}
dataset = buildDataset(titles, x, values);
dataset.addSeries(SeperateY1);
} else {
dataset = buildDataset(titles, x, values);
}
XYSeries seriesMin1, seriesMin2, seriesMin3, seriesMin4, seriesMin5, seriesMin6, seriesMin7, seriesMin8, seriesMin9, seriesMin10, seriesMin11, seriesMin12;
if (!mHeightInCmsMonthDate.isEmpty()) {
seriesMin1 = dataset.getSeriesAt(0);
seriesMin2 = dataset.getSeriesAt(1);
seriesMin3 = dataset.getSeriesAt(2);
seriesMin4 = dataset.getSeriesAt(3);
seriesMin5 = dataset.getSeriesAt(4);
seriesMin6 = dataset.getSeriesAt(5);
seriesMin1.addAnnotation("3%", 37,
mHeightMonth3.get(mHeightMonth3.size() - 1));
seriesMin2.addAnnotation("25%", 37,
mHeightMonth25.get(mHeightMonth25.size() - 1));
seriesMin3.addAnnotation("50%", 37,
mHeightMonth50.get(mHeightMonth50.size() - 1));
seriesMin4.addAnnotation("75%", 37,
mHeightMonth75.get(mHeightMonth75.size() - 1));
seriesMin5.addAnnotation("97%", 37,
mHeightMonth97.get(mHeightMonth97.size() - 1));
for (int i = 0; i < mHeightInCmsMonthDate.size(); i++) {
seriesMin6.addAnnotation("(" + mHeightInCmsMonthDate.get(i)
+ " , " + mHeightValueCms.get(i) + ")",
mHeightInCmsMonthDate.get(i), mHeightValueCms.get(i));
}
} else {
seriesMin1 = dataset.getSeriesAt(0);
seriesMin2 = dataset.getSeriesAt(1);
seriesMin3 = dataset.getSeriesAt(2);
seriesMin4 = dataset.getSeriesAt(3);
seriesMin5 = dataset.getSeriesAt(4);
seriesMin1.addAnnotation("3%", 37,
mHeightMonth3.get(mHeightMonth3.size() - 1));
seriesMin2.addAnnotation("25%", 37,
mHeightMonth25.get(mHeightMonth25.size() - 1));
seriesMin3.addAnnotation("50%", 37,
mHeightMonth50.get(mHeightMonth50.size() - 1));
seriesMin4.addAnnotation("75%", 37,
mHeightMonth75.get(mHeightMonth75.size() - 1));
seriesMin5.addAnnotation("97%", 37,
mHeightMonth97.get(mHeightMonth97.size() - 1));
}
values.clear();
List<double[]> values1 = new ArrayList<double[]>();
List<double[]> values2 = new ArrayList<double[]>();
List<double[]> values3 = new ArrayList<double[]>();
List<double[]> values4 = new ArrayList<double[]>();
List<double[]> values5 = new ArrayList<double[]>();
List<double[]> values6 = new ArrayList<double[]>();
values1.add(new double[] { mWeightMonth97.get(0),
mWeightMonth97.get(1), mWeightMonth97.get(2),
mWeightMonth97.get(3), mWeightMonth97.get(4),
mWeightMonth97.get(5), mWeightMonth97.get(6),
mWeightMonth97.get(7), mWeightMonth97.get(8),
mWeightMonth97.get(9), mWeightMonth97.get(10),
mWeightMonth97.get(11), mWeightMonth97.get(12) });
addXYSeries(dataset, new String[] { "97%" }, x, values1, 1);
values2.add(new double[] { mWeightMonth75.get(0),
mWeightMonth75.get(1), mWeightMonth75.get(2),
mWeightMonth75.get(3), mWeightMonth75.get(4),
mWeightMonth75.get(5), mWeightMonth75.get(6),
mWeightMonth75.get(7), mWeightMonth75.get(8),
mWeightMonth75.get(9), mWeightMonth75.get(10),
mWeightMonth75.get(11), mWeightMonth75.get(12) });
addXYSeries(dataset, new String[] { "75%" }, x, values2, 1);
values3.add(new double[] { mWeightMonth50.get(0),
mWeightMonth50.get(1), mWeightMonth50.get(2),
mWeightMonth50.get(3), mWeightMonth50.get(4),
mWeightMonth50.get(5), mWeightMonth50.get(6),
mWeightMonth50.get(7), mWeightMonth50.get(8),
mWeightMonth50.get(9), mWeightMonth50.get(10),
mWeightMonth50.get(11), mWeightMonth50.get(12) });
addXYSeries(dataset, new String[] { "50%" }, x, values3, 1);
values4.add(new double[] { mWeightMonth25.get(0),
mWeightMonth25.get(1), mWeightMonth25.get(2),
mWeightMonth25.get(3), mWeightMonth25.get(4),
mWeightMonth25.get(5), mWeightMonth25.get(6),
mWeightMonth25.get(7), mWeightMonth25.get(8),
mWeightMonth25.get(9), mWeightMonth25.get(10),
mWeightMonth25.get(11), mWeightMonth25.get(12) });
addXYSeries(dataset, new String[] { "25%" }, x, values4, 1);
values5.add(new double[] { mWeightMonth3.get(0), mWeightMonth3.get(1),
mWeightMonth3.get(2), mWeightMonth3.get(3),
mWeightMonth3.get(4), mWeightMonth3.get(5),
mWeightMonth3.get(6), mWeightMonth3.get(7),
mWeightMonth3.get(8), mWeightMonth3.get(9),
mWeightMonth3.get(10), mWeightMonth3.get(11),
mWeightMonth3.get(12) });
addXYSeries(dataset, new String[] { "3% (Weight)" }, x, values5, 1);
double[] WeightInKg = null;
if (!mWeightValueKg.isEmpty() && !mWeightInKgMonthDate.isEmpty()) {
WeightInKg = new double[mWeightValueKg.size()];
for (int i = 0; i < mWeightValueKg.size(); i++) {
WeightInKg[i] = mWeightValueKg.get(i);
}
values6.add(WeightInKg);
double[] dateValue = new double[mWeightInKgMonthDate.size()];
for (int i = 0; i < mWeightInKgMonthDate.size(); i++) {
dateValue[i] = mWeightInKgMonthDate.get(i);
}
x1.add(dateValue);
addXYSeries(dataset, new String[] { "" }, x1, values6, 1);
}
if (!mHeightInCmsMonthDate.isEmpty()) {
seriesMin7 = dataset.getSeriesAt(6);
seriesMin8 = dataset.getSeriesAt(7);
seriesMin9 = dataset.getSeriesAt(8);
seriesMin10 = dataset.getSeriesAt(9);
seriesMin11 = dataset.getSeriesAt(10);
seriesMin7.addAnnotation("3%", 37,
mWeightMonth3.get(mWeightMonth3.size() - 1));
seriesMin8.addAnnotation("25%", 37,
mWeightMonth25.get(mWeightMonth25.size() - 1));
seriesMin9.addAnnotation("50%", 37,
mWeightMonth50.get(mWeightMonth50.size() - 1));
seriesMin10.addAnnotation("75%", 37,
mWeightMonth75.get(mWeightMonth75.size() - 1));
seriesMin11.addAnnotation("97%", 37,
mWeightMonth97.get(mWeightMonth97.size() - 1));
if (!mWeightInKgMonthDate.isEmpty()) {
seriesMin12 = dataset.getSeriesAt(11);
for (int i = 0; i < mWeightInKgMonthDate.size(); i++) {
seriesMin12.addAnnotation("(" + mWeightInKgMonthDate.get(i)
+ " , " + WeightInKg[i] + ")",
mWeightInKgMonthDate.get(i), WeightInKg[i]);
}
}
} else {
seriesMin6 = dataset.getSeriesAt(5);
seriesMin7 = dataset.getSeriesAt(6);
seriesMin8 = dataset.getSeriesAt(7);
seriesMin9 = dataset.getSeriesAt(8);
seriesMin10 = dataset.getSeriesAt(9);
seriesMin6.addAnnotation("3%", 37,
mWeightMonth3.get(mWeightMonth3.size() - 1));
seriesMin7.addAnnotation("25%", 37,
mWeightMonth25.get(mWeightMonth25.size() - 1));
seriesMin8.addAnnotation("50%", 37,
mWeightMonth50.get(mWeightMonth50.size() - 1));
seriesMin9.addAnnotation("75%", 37,
mWeightMonth75.get(mWeightMonth75.size() - 1));
seriesMin10.addAnnotation("97%", 37,
mWeightMonth97.get(mWeightMonth97.size() - 1));
if (!mWeightInKgMonthDate.isEmpty()) {
seriesMin11 = dataset.getSeriesAt(10);
for (int i = 0; i < mWeightInKgMonthDate.size(); i++) {
seriesMin11.addAnnotation("(" + mWeightInKgMonthDate.get(i)
+ " , " + WeightInKg[i] + ")",
mWeightInKgMonthDate.get(i), WeightInKg[i]);
}
}
}
GraphicalView mView = ChartFactory.getCubeLineChartView(context,
dataset, renderer, 0.3f);
return mView;
}
解决方案
sorry the problem was with the logic i have used above ,I have changed the line
if (!(mWeightInKgMonthDate.isEmpty() && mHeightInCmsMonthDate.isEmpty()))
to
if (!mWeightInKgMonthDate.isEmpty() && !mHeightInCmsMonthDate.isEmpty())
thats it..