我正在尝试使用achart引擎开发应用程序,该应用程序绘制具有多个系列的图表。
这是我的代码:
import java.util.ArrayList;
import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import android.content.Context;
import android.graphics.Color;
public class Graph {
private Context context;
XYMultipleSeriesDataset dataset;
XYMultipleSeriesRenderer renderer;
public static boolean ClickEnabled = true;
public Graph(Context context) {
this.context = context;
}
public void initData(ArrayList<Double> x,ArrayList<Double> y,ArrayList<Double> z){
XYSeries seriesX = new XYSeries("X");
for(int i =0 ; i< x.size();i++){
seriesX.add(x.get(i), i);
}
XYSeries seriesY = new XYSeries("Y");
for(int i =0 ; i< y.size();i++){
seriesY.add(y.get(i), i);
}
XYSeries seriesZ = new XYSeries("Z");
for(int i =0 ; i< z.size();i++){
seriesZ.add(z.get(i), i);
}
dataset = new XYMultipleSeriesDataset();
dataset.addSeries(seriesX);
dataset.addSeries(seriesY);
dataset.addSeries(seriesZ);
renderer = new XYMultipleSeriesRenderer();
}
public void setProperties(){
renderer.setPanEnabled(true, false);
renderer.setClickEnabled(ClickEnabled);
renderer.setBackgroundColor(Color.WHITE);
renderer.setApplyBackgroundColor(true);
renderer.setChartTitle("AccelerometerData");
renderer.setAxesColor(Color.BLACK);
XYSeriesRenderer renderer1 = new XYSeriesRenderer();
renderer1.setColor(Color.RED);
renderer1.setPointStyle(PointStyle.DIAMOND);
renderer.addSeriesRenderer(renderer1);
XYSeriesRenderer renderer2 = new XYSeriesRenderer();
renderer2.setColor(Color.GREEN);
renderer2.setPointStyle(PointStyle.DIAMOND);
renderer.addSeriesRenderer(renderer2);
XYSeriesRenderer renderer3 = new XYSeriesRenderer();
renderer3.setColor(Color.BLUE);
renderer3.setPointStyle(PointStyle.DIAMOND);
renderer.addSeriesRenderer(renderer3);
}
public GraphicalView getGraph(){
return ChartFactory.getLineChartView(context, dataset, renderer);
}
}
我得到这样的图表:
我希望所有三个系列平行,并希望从图表中删除黑色背景;
最佳答案
对于更改黑色,您可以这样做
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setMargins(new int[] { top, left, bottom, right });
renderer.setMarginsColor(Color.RED);
对于第二个问题,请通过屏幕截图或任何参考图片更具体地说明问题。