紧接着android绘画折线图一,下面来介绍第二种方法,使用该方法,首先需要一个Androidplot-core-0.4.3-release.jar,该jar包之后也包含在项目源码中

建立一个android项目:

  1. import android.app.Activity;
  2. import android.graphics.Color;
  3. import android.os.Bundle;
  4. import com.androidplot.xy.SimpleXYSeries;
  5. import com.androidplot.series.XYSeries;
  6. import com.androidplot.xy.*;
  7.  
  8. import java.util.Arrays;
  9.  
  10. public class SimpleXYPlot extends Activity
  11. {
  12.  
  13. private XYPlot mySimpleXYPlot;
  14.  
  15. @Override
  16. public void onCreate(Bundle savedInstanceState)
  17. {
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.main);
  20.  
  21. // Initialize our XYPlot reference:
  22. mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
  23.  
  24. // Create two arrays of y-values to plot:
  25. Number[] series1Numbers = {1, 8, 5, 2, 7, 4};
  26. Number[] series2Numbers = {4, 6, 3, 8, 2, 10};
  27.  
  28. // Turn the above arrays into XYSeries:
  29. XYSeries series1 = new SimpleXYSeries(
  30. Arrays.asList(series1Numbers), // SimpleXYSeries takes a List so turn our array into a List
  31. SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value
  32. "Series1"); // Set the display title of the series
  33. //SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED;
  34. // Same as above, for series2
  35. XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
  36. "Series2");
  37.  
  38. // Create a formatter to use for drawing a series using LineAndPointRenderer:
  39. LineAndPointFormatter series1Format = new LineAndPointFormatter(
  40. Color.rgb(0, 200, 0), // line color
  41. Color.rgb(0, 100, 0), // point color
  42. null); // fill color (optional)
  43.  
  44. // Add series1 to the xyplot:
  45. mySimpleXYPlot.addSeries(series1, series1Format);
  46.  
  47. // Same as above, with series2:
  48. mySimpleXYPlot.addSeries(series2, new LineAndPointFormatter(Color.rgb(0, 0, 200), Color.rgb(0, 0, 100),
  49. Color.rgb(150, 150, 190)));
  50.  
  51. // Reduce the number of range labels
  52. mySimpleXYPlot.setTicksPerRangeLabel(3);
  53. mySimpleXYPlot.setTicksPerDomainLabel(1);
  54.  
  55. // By default, AndroidPlot displays developer guides to aid in laying out your plot.
  56. // To get rid of them call disableAllMarkup():
  57. mySimpleXYPlot.disableAllMarkup();
  58. }
  59. }

这种方法需要用到布局文件,接下来看一下main.xml文件

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent">
  6.  
  7. <com.androidplot.xy.XYPlot
  8. android:id="@+id/mySimpleXYPlot"
  9. android:layout_width="fill_parent"
  10. android:layout_height="fill_parent"
  11. android:layout_marginTop="10px"
  12. android:layout_marginLeft="10px"
  13. android:layout_marginRight="10px"
  14. title="A Simple XYPlot Example"/>
  15. </LinearLayout>

然后运行项目,就出来了一个折线图的效果了

注明:项目源码SimpleXYPlot.zip,Androidplot-core-0.4.3-release.jar包含在其中

android绘画折线图二的更多相关文章

  1. android绘画折线图一

    最近需要实现用android来画折线图,所以百度了一下,发现确实很多,也很乱,现在整理两种方法(第二种方法在[android绘画折线图二]中实现),仅供大家参考,一起学习研究. 第一种使用ChartF ...

  2. Android自定义控件-折线图

    好长时间没有更新博客了,终于可以抽出时间写点东西了,写点什么呢?最近在qq群里边有人问,下边的这个控件怎么画?如下图所示:图可以左右拖动,直到显示完全为止.刚开始看到这个效果图,我也想了一下总共分为以 ...

  3. Android自定义折线图

    老师布置了个作业:http://www.cnblogs.com/qingxu/p/5316897.html 作业中提到的 “玩了几天以后,大家发现了一些很有意思的现象,比如黄金点在逐渐地往下移动.” ...

  4. android 自定义折线图

    看图: 比较简陋,主要是通过canvas画上去的: package com.example.democurvegraph.view; import java.util.ArrayList; impor ...

  5. IOS折线图二

    上周把项目的折线图给做了下,今天想着把它完善完善,自己设置了不同的数据源来测试,哈哈,还真遇到问题了, 就是给图表设置折点数为0时,视图显示的还是原来的,由于数据为空,应该将其设置为空,所以想着怎么把 ...

  6. matplotlib常见绘图基础代码小结:折线图、散点图、条形图、直方图、饼图

    一.折线图 二.散点图 三.条形图 四.直方图 五.饼图 一.折线图折线图用于显示随时间或有序类别的变化趋势 from matplotlib import pyplot as plt x = rang ...

  7. 最牛逼android上的图表库MpChart(二) 折线图

    最牛逼android上的图表库MpChart二 折线图 MpChart折线图介绍 MpChart折线图实例 MpChart效果 最牛逼android上的图表库MpChart(二) 折线图 最近工作中, ...

  8. Android图表引擎AChartEngine之折线图使用

    最近在帮老师做一个课题,其中app端需要显示折线图以便直观地看数据波动,上网查了些资料后发现了这款图标引擎,另外感谢李坤老师的博客,帮助很大. 废话不多说,下面写代码. 一.AChartEngine是 ...

  9. Android图表库MPAndroidChart(二)——线形图的方方面面,看完你会回来感谢我的

    Android图表库MPAndroidChart(二)--线形图的方方面面,看完你会回来感谢我的 在学习本课程之前我建议先把我之前的博客看完,这样对整体的流程有一个大致的了解 Android图表库MP ...

随机推荐

  1. Android Manifest.xml详解

    一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activiti ...

  2. 钉子和小球_DP

    Description 有一个三角形木板,竖直立放,上面钉着n(n+1)/2颗钉子,还有(n+1)个格子(当n=5时如图1).每颗钉子和周围的钉子的距离都等于d,每个格子的宽度也都等于d,且除了最左端 ...

  3. [图论]Floyd 算法小结

    Floyd 算法小结  By Wine93 2013.11 1. Floyd算法简介 Floyd算法利用动态规划思想可以求出任意2点间的最短路径,时间复杂度为O(n^3),对于稠密图, 效率要高于执行 ...

  4. 程序退出异常_DebugHeapDelete和std::numpunct

    前几天程序新加一个功能之后,其中用到了boost的lexical_cast<float>,发现在关闭命令行窗口的时候,程序报错,是程序退出清理时候报的错误. 一开始以为是程序新增的功能有问 ...

  5. 解决织梦标签artlist不能调用副栏目的问题?

    本文转自:http://www.xinshou5.com/a/127.html 织梦列表页中不支持artlist这个标签,这样怎么调用副栏目? 想要在列表页调用副栏目,但是列表页不支持artlist这 ...

  6. Cloud Foundry 在 Azure 中国正式发布

    Cloud Foundry 今天在 Azure 中国上正式发布了!这对于 Azure 平台,以及开源社区都是一个令人振奋的里程碑. Cloud Foundry 简化了云计算应用程序的构建,测试,发布和 ...

  7. 五 浅谈CPU 并行编程和 GPU 并行编程的区别

    前言 CPU 的并行编程技术,也是高性能计算中的热点,也是今后要努力学习的方向.那么它和 GPU 并行编程有何区别呢? 本文将做出详细的对比,分析各自的特点,为将来深入学习 CPU 并行编程技术打下铺 ...

  8. 二 J2EE 概述

    一 WEB 应用 1. WEB 应用工作方式:B/S 模式 (浏览器/服务器模式) 2. WEB 应用结构组成: a. WEB 服务器:是安装在 WEB 服务器计算机上的一个软件包,负责接收用户请求并 ...

  9. 关于环境变量PATH的几点注意事项

    查看执行文件路径变量PATH的内容可用echo $PATH.echo表示显示打印之意,$表示后接的是变量. 如下图所示,其中每个目录中间用冒号(:)来隔开,每个目录是有顺序之分的: 如果预修改PATH ...

  10. 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp

    QSC and Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...