XCL-Charts画面积图(AreaChart) 例1

来源:互联网 发布:有了域名能干什么 编辑:程序博客网 时间:2024/06/05 15:33

     面积图的一个例子,做面积图时发现注释位置放图上方更好处理。改了下。 面积图的网格和轴处理与其它图不一样,

它是用覆盖的范围来表示其势力范围,标签轴无需在突出一段出来。这里处理了下。



   代码:

/** * Copyright 2014  XCL-Charts *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *     http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *  * @Project XCL-Charts  * @Description Android图表基类库 * @author XiongChuanLiang<br/>(xcl_168@aliyun.com) * @Copyright Copyright (c) 2014 XCL-Charts (www.xclcharts.com) * @license http://www.apache.org/licenses/  Apache v2 License * @version v0.1 */package com.demo.xclcharts.view;import java.util.LinkedList;import java.util.List;import org.xclcharts.chart.AreaChart;import org.xclcharts.chart.AreaData;import org.xclcharts.renderer.XEnum;import android.content.Context;import android.graphics.Color;import android.util.Log;/** * @ClassName AreaChart01View * @Description  面积图例子 * @author XiongChuanLiang<br/>(xcl_168@aliyun.com) */public class AreaChart01View extends GraphicalView {//标签集合private LinkedList<String> mChartLabels = new LinkedList<String>();//数据集合private LinkedList<AreaData> mChartDataSet = new LinkedList<AreaData>();public AreaChart01View(Context context) {super(context);// TODO Auto-generated constructor stubchartLabels();chartDataSet();chartRender();}private void chartRender(){try{AreaChart chart = new AreaChart(); //柱形图所占范围大小chart.setChartRange(0.0f, 0.0f,getScreenWidth(),getScreenHeight());chart.setCanvas(this.mCacheCanvas);chart.setPadding(15, 30, 10, 5);//轴数据源//标签轴chart.setLabels(mChartLabels);//数据轴chart.setDataSource(mChartDataSet);//数据轴最大值chart.getDataAxis().setAxisMax(100);//数据轴刻度间隔chart.getDataAxis().setAxisSteps(10);//背景网格chart.getPlotGrid().setEvenRowsFillVisible(true);chart.getPlotGrid().setOddRowsFillVisible(true);//标题chart.setChartTitle("区域图(Area Chart)");chart.setChartSubTitle("(XCL-Charts Demo)");//图例chart.getLegend().setLowerLegend("(年份)");//透明度//chart.setAreaAlpha(200);//显示键值chart.setPlotKeyVisible(true);//绘制chart.render();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();Log.e("ERROR-AreaChart01View", e.toString());}}private void chartDataSet(){//将标签与对应的数据集分别绑定//标签对应的数据集List<Double> dataSeries1= new LinkedList<Double>();dataSeries1.add((double)55); dataSeries1.add((double)60); dataSeries1.add((double)71); dataSeries1.add((double)40);dataSeries1.add((double)35);List<Double> dataSeries2 = new LinkedList<Double>();dataSeries2.add((double)10); dataSeries2.add((double)22); dataSeries2.add((double)30); dataSeries2.add((double)30); dataSeries2.add((double)15); //设置每条线各自的显示属性//key,数据集,线颜色,区域颜色AreaData line1 = new AreaData("小熊",dataSeries1,Color.BLUE,Color.YELLOW);//不显示点line1.setDotStyle(XEnum.DotStyle.HIDE);AreaData line2 = new AreaData("小小熊",dataSeries2,(int)Color.rgb(79, 200, 100),Color.GREEN);//设置线上每点对应标签的颜色line2.getPlotLabelsPaint().setColor(Color.RED);//设置点标签line2.setLineLabelVisible(true);mChartDataSet.add(line1);mChartDataSet.add(line2);}private void chartLabels(){mChartLabels.add("2010");mChartLabels.add("2011");mChartLabels.add("2012");mChartLabels.add("2013");mChartLabels.add("2014");}}



MAIL:  xcl_168@aliyun.com

BLOG: http://blog.csdn.net/xcl168



1 0
原创粉丝点击