android绘画折线图二
紧接着android绘画折线图一,下面来介绍第二种方法,使用该方法,首先需要一个Androidplot-core-0.4.3-release.jar,该jar包之后也包含在项目源码中
建立一个android项目:
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.series.XYSeries;
import com.androidplot.xy.*; import java.util.Arrays; public class SimpleXYPlot extends Activity
{ private XYPlot mySimpleXYPlot; @Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main); // Initialize our XYPlot reference:
mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot); // Create two arrays of y-values to plot:
Number[] series1Numbers = {1, 8, 5, 2, 7, 4};
Number[] series2Numbers = {4, 6, 3, 8, 2, 10}; // Turn the above arrays into XYSeries:
XYSeries series1 = new SimpleXYSeries(
Arrays.asList(series1Numbers), // SimpleXYSeries takes a List so turn our array into a List
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value
"Series1"); // Set the display title of the series
//SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED;
// Same as above, for series2
XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
"Series2"); // Create a formatter to use for drawing a series using LineAndPointRenderer:
LineAndPointFormatter series1Format = new LineAndPointFormatter(
Color.rgb(0, 200, 0), // line color
Color.rgb(0, 100, 0), // point color
null); // fill color (optional) // Add series1 to the xyplot:
mySimpleXYPlot.addSeries(series1, series1Format); // Same as above, with series2:
mySimpleXYPlot.addSeries(series2, new LineAndPointFormatter(Color.rgb(0, 0, 200), Color.rgb(0, 0, 100),
Color.rgb(150, 150, 190))); // Reduce the number of range labels
mySimpleXYPlot.setTicksPerRangeLabel(3);
mySimpleXYPlot.setTicksPerDomainLabel(1); // By default, AndroidPlot displays developer guides to aid in laying out your plot.
// To get rid of them call disableAllMarkup():
mySimpleXYPlot.disableAllMarkup();
}
}
这种方法需要用到布局文件,接下来看一下main.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> <com.androidplot.xy.XYPlot
android:id="@+id/mySimpleXYPlot"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
title="A Simple XYPlot Example"/>
</LinearLayout>
然后运行项目,就出来了一个折线图的效果了
注明:项目源码SimpleXYPlot.zip,Androidplot-core-0.4.3-release.jar包含在其中
android绘画折线图二的更多相关文章
- android绘画折线图一
最近需要实现用android来画折线图,所以百度了一下,发现确实很多,也很乱,现在整理两种方法(第二种方法在[android绘画折线图二]中实现),仅供大家参考,一起学习研究. 第一种使用ChartF ...
- Android自定义控件-折线图
好长时间没有更新博客了,终于可以抽出时间写点东西了,写点什么呢?最近在qq群里边有人问,下边的这个控件怎么画?如下图所示:图可以左右拖动,直到显示完全为止.刚开始看到这个效果图,我也想了一下总共分为以 ...
- Android自定义折线图
老师布置了个作业:http://www.cnblogs.com/qingxu/p/5316897.html 作业中提到的 “玩了几天以后,大家发现了一些很有意思的现象,比如黄金点在逐渐地往下移动.” ...
- android 自定义折线图
看图: 比较简陋,主要是通过canvas画上去的: package com.example.democurvegraph.view; import java.util.ArrayList; impor ...
- IOS折线图二
上周把项目的折线图给做了下,今天想着把它完善完善,自己设置了不同的数据源来测试,哈哈,还真遇到问题了, 就是给图表设置折点数为0时,视图显示的还是原来的,由于数据为空,应该将其设置为空,所以想着怎么把 ...
- matplotlib常见绘图基础代码小结:折线图、散点图、条形图、直方图、饼图
一.折线图 二.散点图 三.条形图 四.直方图 五.饼图 一.折线图折线图用于显示随时间或有序类别的变化趋势 from matplotlib import pyplot as plt x = rang ...
- 最牛逼android上的图表库MpChart(二) 折线图
最牛逼android上的图表库MpChart二 折线图 MpChart折线图介绍 MpChart折线图实例 MpChart效果 最牛逼android上的图表库MpChart(二) 折线图 最近工作中, ...
- Android图表引擎AChartEngine之折线图使用
最近在帮老师做一个课题,其中app端需要显示折线图以便直观地看数据波动,上网查了些资料后发现了这款图标引擎,另外感谢李坤老师的博客,帮助很大. 废话不多说,下面写代码. 一.AChartEngine是 ...
- Android图表库MPAndroidChart(二)——线形图的方方面面,看完你会回来感谢我的
Android图表库MPAndroidChart(二)--线形图的方方面面,看完你会回来感谢我的 在学习本课程之前我建议先把我之前的博客看完,这样对整体的流程有一个大致的了解 Android图表库MP ...
随机推荐
- IOS 使用block完成网络请求的自定义类BlockURLConnection
一,头文件 #import <Foundation/Foundation.h>//定义下载中block类型typedef void(^ProcessBlock) (NSURLRespons ...
- Windows 7下安装部署NodeJs
第一步 安装NodeJs http://nodejs.org/download/ 下载windows版本的msi文件,双击进行安装即可.安装完毕,默认安装路径为C:\Program Files\no ...
- iOS开发环境C语言基础 数组 函数
1 求数组元素的最大值 1.1 问题 创建程序,实现查询数组中最大值的功能,需求为:创建一个长度为10的数组,数组内放置10个0~99之间(包含0,包含99)的随机数作为数组内容,要求查询出数组中的最 ...
- linux 网络联接
安装完进入系统以后需要配置ip 方法一:图形界面直接配置,在system下的prefrecens下面的network下面设置 方法二: 在安装虚拟机的时候选择“bridge networking ”网 ...
- 使用jQuery设置disabled属性与移除disabled属性
Readonly只针对input和textarea有效,而disabled对于所有的表单元素都有效,下面为大家介绍下使用jQuery设置disabled属性 表单中readOnly和disable ...
- JQuery中操作Css样式
//1.获取和设置样式 $("#tow").attr("class")获取ID为tow的class属性 $("#two").attr(&qu ...
- 150. Evaluate Reverse Polish Notation
Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: ...
- sublime text3 本地化
博客園中搜到n篇 同題日誌 沒一篇靠譜 超級反感這種行為,浪費別人的時間無異於謀財害命 自動: Control+` (注意不是cmd+p) import urllib.request,os,hashl ...
- ES6-Symbol
javaScript的数据类型:number,string,boolean,undefined,null,object ES6带来了一个新的数据类型:symbol 目的是:解决对象的属性名冲突的问题. ...
- Qt 串口学习2
未命名 (2) 1 新建串口 //new serial portmy_serialport= new QSerialPort(); 2给串口设定名字 my_serialport->setPort ...