zoukankan      html  css  js  c++  java
  • App_显示图表内容

    今天在之前记账本的基础上增加了图标的显示功能,在本次课程中它以折线图为例讲述。但是课程中给出了多有图的代码案例。

     https://github.com/lecho/hellocharts-android

    但是结果并不是很理想,中途进行了很多色测试,没有出现问题,但是在做后图表的显示中出现了闪退的问题,根据网上所说的我进行了配置的更改,但是依旧无效,继续明天的努力,解决闪退bug的问题把

    这里并没有下载和复制图标源码,而是在build.gradle里面做了引用

     并在这里对以上的内容在chart_view.xml中做了引用

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="10dp">
    
        <lecho.lib.hellocharts.view.LineChartView
            android:id="@+id/chart"
            android:padding="20dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />
    
    </LinearLayout>

    并且新建了相对应的ChartsActivity.java:

    package com.example.familybook_hu;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    import androidx.annotation.Nullable;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
    import java.util.TreeMap;
    
    import lecho.lib.hellocharts.model.Line;
    import lecho.lib.hellocharts.model.LineChartData;
    import lecho.lib.hellocharts.model.PointValue;
    import lecho.lib.hellocharts.model.ValueShape;
    import lecho.lib.hellocharts.util.ChartUtils;
    import lecho.lib.hellocharts.view.LineChartView;
    
    public class ChartsActivity extends Activity {
    
        private LineChartView mChart;
        private Map<String,Integer> table=new TreeMap<>();//合并之后的数据源
        private LineChartData mData;
    
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.chart_view);
            mChart=(LineChartView) findViewById(R.id.chart);
            mData=new LineChartData();
            List<CostBean> allDate= (List<CostBean>) getIntent().getSerializableExtra("cost_list");
            generateValues(allDate);//合并同一天数据
            generateData();
        }
    
        private void generateData() {
            List<Line> lines=new ArrayList<>();
            List<PointValue> values=new ArrayList<>();
            int indeX=0;
            for(Integer value:table.values()){
                //通过循环生成相对应的点
                values.add(new PointValue(indeX,value));
                indeX++;
            }
            //将产生的点进行连接生成线
            Line line=new Line(values);
            line.setColor(ChartUtils.COLORS[0]);
            line.setShape(ValueShape.CIRCLE);
            line.setPointColor(ChartUtils.COLORS[1]);
            lines.add(line);
            mData =new LineChartData(lines);
            mData.setLines(lines);
            mChart.setLineChartData(mData);
        }
    
        private void generateValues(List<CostBean> allDate) {
            //将同一天数据进行累加,并且将算好放到数据源table中
            if(allDate!=null){
                for(int i=0;i<allDate.size();i++){
                    CostBean costBean=allDate.get(i);//去除全部数值
                    String costDate=costBean.costDate;
                    int costMoney=Integer.parseInt(costBean.costMoney);
                    if(!table.containsKey(costDate)){
                        table.put(costDate,costMoney);
                    }
                    else{
                        int originMoney=table.get(costDate);
                        table.put(costDate,originMoney+costMoney);
                    }
                }
            }
        }
    }
     
  • 相关阅读:
    【Language】 TIOBE Programming Community Index for February 2013
    【diary】good health, good code
    【web】a little bug of cnblog
    【Git】git bush 常用命令
    【web】Baidu zone ,let the world know you
    【diary】help others ,help yourself ,coding is happiness
    【Git】Chinese messy code in widows git log
    【windows】add some font into computer
    SqlServer启动参数配置
    关于sqlserver中xml数据的操作
  • 原文地址:https://www.cnblogs.com/hhjing/p/12332934.html
Copyright © 2011-2022 走看看