哼哼,网上找了半天都不全,所以决定自己写一个完整的可以直接贴代码的

test.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <lecho.lib.hellocharts.view.ComboLineColumnChartView
android:id="@+id/combochart"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
AddColumnLineData.java(专门用于添加数据)
package com.shaoxin.myhellocharts;

import android.graphics.Color;

import java.util.ArrayList;
import java.util.List; import lecho.lib.hellocharts.gesture.ZoomType;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.AxisValue;
import lecho.lib.hellocharts.model.Column;
import lecho.lib.hellocharts.model.ColumnChartData;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.model.SubcolumnValue;
import lecho.lib.hellocharts.model.ValueShape;
import lecho.lib.hellocharts.util.ChartUtils;
import lecho.lib.hellocharts.view.ColumnChartView; import static com.shaoxin.myhellocharts.LineColumn.comboChart; /**
* Created by shaoxin on 2016/12/22.
*/ public class AddColumnLineData { public final static String[] months = new String[]{"Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",};
public static ColumnChartView columnChart;
public static List<AxisValue> axisValues; //设置折线图,添加设置好的数据
public static LineChartData initLineCharData(List<Line> dataLine) {
LineChartData lineCharData = new LineChartData(dataLine);
//初始化轴
Axis axisX = new Axis().setHasLines(true);
Axis axisY = new Axis().setHasLines(true);
axisX.setName("时间");
axisY.setName("销量");
lineCharData.setAxisYLeft(axisY);
lineCharData.setAxisXBottom(axisX);
return lineCharData;
} //定义方法设置折线图中数据
public static List<Line> initDataLine() {
List<Line> lineList = new ArrayList<>();
List<PointValue> pointValueList = new ArrayList<>(); int numLines = months.length;
for (int i = 0; i < numLines; ++i) {
pointValueList.add(new PointValue(i, (float) Math.random() * 50f + 5));
axisValues.add(new AxisValue(i).setLabel(months[i]));
} Line line = new Line(pointValueList);
line.setColor(Color.RED);
line.setShape(ValueShape.CIRCLE);
line.setHasLabelsOnlyForSelected(true);
lineList.add(line); return lineList;
} //定义方法设置柱状图中数据
public static ColumnChartData initColumnCharData(List<Column> dataLine) {
ColumnChartData columnData = new ColumnChartData(dataLine); columnData.setAxisXBottom(new Axis(axisValues).setHasLines(true)
.setTextColor(Color.BLACK));
columnData.setAxisYLeft(new Axis().setHasLines(true)
.setTextColor(Color.BLACK).setMaxLabelChars(2));
// Set selection mode to keep selected month column highlighted.
comboChart.setValueSelectionEnabled(true);
comboChart.setZoomType(ZoomType.HORIZONTAL); return columnData;
} //定义方法设置柱状图中数据
public static List<Column> initColumnLine() {
List<Column> list = new ArrayList<>();
List<SubcolumnValue> subcolumnValueList;
axisValues = new ArrayList<AxisValue>();
int numSubcolumns = 1;
int numColumns = months.length;
for (int i = 0; i < numColumns; ++i) {
subcolumnValueList = new ArrayList<SubcolumnValue>();
for (int j = 0; j < numSubcolumns; ++j) {
subcolumnValueList.add(new SubcolumnValue((float) Math.random() * 50f + 5,
ChartUtils.pickColor()));
}
// 点击柱状图就展示数据量
axisValues.add(new AxisValue(i).setLabel(months[i]));
list.add(new Column(subcolumnValueList).setHasLabelsOnlyForSelected(true));
}
return list;
} }
LineColumn.java
package com.shaoxin.myhellocharts;

import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity; import java.util.List; import lecho.lib.hellocharts.listener.ComboLineColumnChartOnValueSelectListener;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.Column;
import lecho.lib.hellocharts.model.ColumnChartData;
import lecho.lib.hellocharts.model.ComboLineColumnChartData;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.model.SubcolumnValue;
import lecho.lib.hellocharts.model.Viewport;
import lecho.lib.hellocharts.view.ComboLineColumnChartView; import static com.shaoxin.myhellocharts.AddColumnLineData.axisValues;
import static com.shaoxin.myhellocharts.AddColumnLineData.initColumnCharData;
import static com.shaoxin.myhellocharts.AddColumnLineData.initColumnLine;
import static com.shaoxin.myhellocharts.AddColumnLineData.initDataLine;
import static com.shaoxin.myhellocharts.AddColumnLineData.initLineCharData; /**
* Created by shaoxin on 2016/12/22.
*/ public class LineColumn extends AppCompatActivity {
static ComboLineColumnChartView comboChart; @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
comboChart = (ComboLineColumnChartView) findViewById(R.id.combochart); comboChart.setZoomEnabled(true);//设置是否支持缩放
//为图表设置值得触摸事件
//设置值触摸侦听器,将触发图表顶部的变化。
comboChart.setOnValueTouchListener(new ComboLineColumnChartOnValueSelectListener() {
@Override
public void onColumnValueSelected(int i, int i1, SubcolumnValue subcolumnValue) { } @Override
public void onPointValueSelected(int i, int i1, PointValue pointValue) { } @Override
public void onValueDeselected() { }
});
//设置图表是否可以与用户互动
comboChart.setInteractive(true);
//设置图表数据是否选中进行显示
comboChart.setValueSelectionEnabled(true);
//定义组合数据对象
ComboLineColumnChartData comboLineColumnChartData = new ComboLineColumnChartData();
//为图表设置数据,数据类型为ComboLineColumnChartData
comboChart.setComboLineColumnChartData(comboLineColumnChartData); //为组合图设置折现图数据
List<Line> dataLine = initDataLine();
LineChartData lineCharData = initLineCharData(dataLine);
lineCharData.setLines(dataLine);
comboLineColumnChartData.setLineChartData(lineCharData); //为组合图设置柱形图数据
List<Column> dataColumn = initColumnLine();
ColumnChartData columnChartData = initColumnCharData(dataColumn);
columnChartData.setColumns(dataColumn);
comboLineColumnChartData.setColumnChartData(columnChartData); comboLineColumnChartData.setValueLabelsTextColor(Color.BLACK);// 设置数据文字颜色
comboLineColumnChartData.setValueLabelTextSize(25);// 设置数据文字大小
comboLineColumnChartData.setValueLabelTypeface(Typeface.MONOSPACE);// 设置数据文字样式 Axis axisX = new Axis().setHasLines(true);
Axis axisY = new Axis().setHasLines(true);
axisX.setValues(axisValues);
axisY.setTextColor(Color.BLACK);
axisY.setTextColor(Color.BLACK);
comboLineColumnChartData.setAxisYLeft(axisY);
comboLineColumnChartData.setAxisXBottom(axisX);
//comboLineColumnChartData.setAxisYRight(axisYRight);//设置右边显示的轴
//comboLineColumnChartData.setAxisXTop(axisXTop);//设置顶部显示的轴
comboChart.setComboLineColumnChartData(comboLineColumnChartData);//为组合图添加数据 Viewport viewport = initViewPort();
comboChart.setMaximumViewport(viewport);
comboChart.setCurrentViewport(viewport);
} private Viewport initViewPort() {
Viewport viewport = new Viewport();
viewport.top = 60;
viewport.bottom = 0;
viewport.left = -2;
viewport.right = 20; return viewport;
} public static ComboLineColumnChartView getComboLineColumnChartView() {
return comboChart;
}
}

觉得有用的话别忘了评论点个赞啥的,没用就忽略

hellocharts的折线图与柱状图的结合之ComboLineColumnChartView的更多相关文章

  1. excel在一个图表内,显示折线图和柱状图

      折线图和柱状图,在同一个图表中拆分显示   一个图,设置主坐标轴 另外一个图,设置次坐标轴     拆分,通过调整纵坐标的最小值和最大值来实现     关于图表的标题,选中图表,选择布局,然后图表 ...

  2. echarts、higncharts折线图或柱状图显示数据为0的点

    echarts.higncharts折线图或柱状图只需要后端传到前端一段json数据,接送数据的x轴与y周有对应数据,折线图或柱状图就会渲染出这数据. 比如,x轴表示美每天日期,y轴表示数量.他们的数 ...

  3. DevExpress 折线图和柱状图的绘制与数据绑定

    DevExpress 组件是一个非常丰富和强大的组件,适合各种可视化图形的绘制与展示,在数据分析展示中是个很有帮助的,网上也有很多关于这方面的文章,关于折线图或柱状图的画法,以下是自己在工作中接触到的 ...

  4. MATLAB之折线图、柱状图、饼图以及常用绘图技巧

    MATLAB之折线图.柱状图.饼图以及常用绘图技巧 一.折线图 参考代码: %图1:各模式直接成本预测 %table0-table1为1*9的数组,记录关键数据 table0 = data_modol ...

  5. Qt数据可视化(散点图、折线图、柱状图、盒须图、饼状图、雷达图)开发实例

    ​  目录 散点图 折线图 柱状图 水平柱状图 水平堆叠图 水平百分比柱状图 盒须图 饼状图 雷达图 Qt散点图.折线图.柱状图.盒须图.饼状图.雷达图开发实例. 在开发过程中我们会使用多各种各样的图 ...

  6. DevExpress使用之ChartControl控件绘制图表(多坐标折线图、柱状图、饼状图)

    最近因为公司项目需要用到WinForm的DecExpress控件,在这里把一些使用方法总结一下. DevExpress中有一个专门用来绘制图表的插件ChartControl,可以绘制折线图.饼状图.柱 ...

  7. VS2010 使用TeeChart画图控件 - 之二 - 绘制图形(折线图,柱状图)

    1.前期准备 详细可见VS2010 使用TeeChart画图控件 - 之中的一个 控件和类的导入 1. 1 加入TeeChart控件,给控件加入变量m_TeeChart 加入TeeChart控件,右击 ...

  8. RDLC报表系列(六) 多图表-折线图和柱状图

    美好的一天开始了,这篇是RDLC系列的最后一篇文章,我的小项目也已经release,正在测试中. 1.新建demo3.aspx和demo3.rdlc文件 2.往rdlc文件中拖一个图标控件,在弹出的窗 ...

  9. Jquery画折线图、柱状图、饼图

    1.今天做了一个折线图,首先需要导js文件.这里有一个demo:http://files.cnblogs.com/files/feifeishi/jquery_zhexiantubingtuzhuzh ...

随机推荐

  1. 【09-27】Spring 学习笔记

    SpringMVC 配置全局异常处理器 import javax.servlet.http.HttpServletResponse; import org.springframework.web.bi ...

  2. System.Web.HttpRequestValidationException: A potentially dangerous Request.F

    ASP.NET .0验证请求 System.Web.HttpRequestValidationException: A potentially dangerous Request.F System.W ...

  3. Apache流处理框架对比

    分布式流处理,类似于MapReduce这样的通用计算模型,但是却要求它能够在毫秒级别或者秒级别完成响应.这些系统可以用DAG表示流处理的拓扑. Points of Interest 在比较不同系统是, ...

  4. jq绑定事件的4种方式

    jQuery提供了多种绑定事件的方式,每种方式各有其特点,明白了它们之间的异同点,有助于我们在写代码的时候进行正确的选择,从而写出优雅而容易维护的代码.下面我们来看下jQuery中绑定事件的方式都有哪 ...

  5. ZOJ Problem Set - 3329(概率DP)

    One Person Game Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge There is a very ...

  6. 搭建Apache Web服务器

    1.下载Apache服务器的安装包 地址:http://httpd.apache.org/download.cgi 从http://archive.apache.org/dist/httpd/bina ...

  7. Thinkphp 3.2.2 验证码check_verify方法,只能验证一次

    问题: Thinkphp 3.2.2 验证码check_verify方法,只能验证一次. function check_verify($code, $id = ''){ $verify = \Thin ...

  8. gd库

    1.开启GD库扩展 去掉注释: extension=php_gd2.dll extension_dir='ext目录所在位置' 2.检测GD库是否开启 phpinfo(); //检测扩展是够开启 ex ...

  9. 配置VMware虚拟机用绕过校园网达到无线上网配置方法

    因为平时要用到Vmware这样的工具上虚拟机上网, 但是本人是学生狗,学生狗在学校就要面对大学毒瘤软件--锐捷,而锐捷是不允许有虚拟网卡的存在的,所以上网只能用wifi上.之前试了很久,反正是怎么开都 ...

  10. iOS企业分发证书制作

    自签名证书制作流程 打开终端,输入 openssl genrsa - ,生成名称为ca的秘钥 注:openssl生成的文件皆放在用户文档下(finder菜单栏'前往' - 电脑 -Macintosh ...