我正在绘制achartengine线图上的大量数据。有大约500点可以绘制。 但我看到x标签超过了一圈,看起来像一条粗线/条! 我正在x轴上以2分钟的间隔绘制时间。 我想要的是不是以2分钟的间隔显示时间,而是希望每小时显示相同的时间,这会将x轴标签降低到12-15左右。
我该怎么做?请帮忙。
这是我的代码。
XYSeries minSeries = new XYSeries("Min");
XYSeries maxSeries = new XYSeries("Max");
XYSeries actualSeries = new XYSeries("Actual");
ArrayList<Double> minDataList = new ArrayList<Double>();
ArrayList<Double> maxDataList = new ArrayList<Double>();
ArrayList<Double> actualDataList = new ArrayList<Double>();
if(jsonData.containsKey("Min")) {
Utility.tokenizeData(jsonData.get("Min"), minDataList);
for (int i =0;i<minDataList.size();i++) {
System.out.println("MIn value in line chart is "+minDataList.get(i));
minSeries.add(i,minDataList.get(i));
}
}
if(jsonData.containsKey("Max")) {
Utility.tokenizeData(jsonData.get("Max"), maxDataList);
for (int i = 0;i<maxDataList.size();i++) {
maxSeries.add(i,maxDataList.get(i));
}
}
int minLen = minDataList.size();
Double minVal = minDataList.get(0);
Double maxValue = maxDataList.get(0);
int actLength = actualDataList.size()-minDataList.size();
for(int a=minLen;a<actLength;a++){
minSeries.add(a,minVal);
maxSeries.add(a,maxValue);
}
if(jsonData.containsKey("Actual")) {
Utility.tokenizeData(jsonData.get("Actual"), actualDataList);
for (int i = 0;i<actualDataList.size();i++) {
actualSeries.add(i,actualDataList.get(i));
}
}
dataset.addSeries(minSeries);
dataset.addSeries(maxSeries);
dataset.addSeries(actualSeries);
// Now we create the renderer
XYSeriesRenderer minrenderer = new XYSeriesRenderer();
minrenderer.setLineWidth(2);
minrenderer.setColor(Color.BLACK);
// Include low and max value
minrenderer.setDisplayBoundingPoints(true);
// we add point markers
minrenderer.setPointStyle(PointStyle.CIRCLE);
minrenderer.setPointStrokeWidth(3);
minrenderer.setDisplayChartValues(true);
minrenderer.setFillPoints(true);
// Now we create the renderer
XYSeriesRenderer maxrenderer = new XYSeriesRenderer();
maxrenderer.setLineWidth(2);
maxrenderer.setColor(Color.YELLOW);
// Include low and max value
maxrenderer.setDisplayBoundingPoints(true);
// we add point markers
//hvacrenderer.setPointStyle(PointStyle.CIRCLE);
maxrenderer.setPointStrokeWidth(3);
maxrenderer.setDisplayChartValues(true);
maxrenderer.setFillPoints(true);
// Now we create the renderer
XYSeriesRenderer actrenderer = new XYSeriesRenderer();
actrenderer.setLineWidth(2);
actrenderer.setColor(Color.parseColor("#FF0000"));
// Include low and max value
actrenderer.setDisplayBoundingPoints(true);
// we add point markers
//lgtrenderer.setPointStyle(PointStyle.CIRCLE);
actrenderer.setPointStrokeWidth(3);
actrenderer.setDisplayChartValues(true);
actrenderer.setFillPoints(true);
mRenderer.addSeriesRenderer(minrenderer);
mRenderer.addSeriesRenderer(maxrenderer);
mRenderer.addSeriesRenderer(actrenderer);
mRenderer.setYAxisMin(-10);
if(jsonData.containsKey(Constant.TAG_CATEGORIES) && jsonData.get(Constant.TAG_CATEGORIES) != null) {
Utility.tokenizeStringData(jsonData.get(Constant.TAG_CATEGORIES), categoryList);
}
for(int l=0;l<categoryList.size();l++){
mRenderer.addXTextLabel(l, (String)categoryList.get(l));
}
mRenderer.setXLabels(20);
mRenderer.setShowCustomTextGrid(true);
// We want to avoid black border
mRenderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00));
// transparent margins // Disable Pan on two axis
mRenderer.setPanEnabled(true, true);
mRenderer.setZoomEnabled(false, false);
// mRenderer.setYAxisMax(3);
//mRenderer.setYAxisMin(0);
//mRenderer.setXAxisMin(0);
mRenderer.setShowGrid(true);
mRenderer.setLabelsTextSize(25.0f);
mRenderer.setLegendTextSize(30.5f);
mRenderer.setChartTitleTextSize(30.0f);
mRenderer.setChartTitle("Temperature");
mRenderer.setAxisTitleTextSize(30.0f);
mRenderer.setYTitle("Celsius(C)");
mRenderer.setMargins(new int[]{20, 30, 50, 0});
mRenderer.setLabelsColor(Color.DKGRAY);
mRenderer.setXLabelsColor(Color.DKGRAY);
mRenderer.setYLabelsColor(0, Color.DKGRAY);
mRenderer.setAxesColor(Color.DKGRAY);
我想绘制所有点,但只显示xaxis标签的子集,以使其看起来干净!
答案 0 :(得分:0)
解决了这个问题,非常简单!
在设置xaxis标签时,只需将循环计数器递增到您喜欢的数字。
for(int l=0;l<categoryList.size();){
mRenderer.addXTextLabel(l, (String)categoryList.get(l));
l=l+30;
}