Giter Club home page Giter Club logo

mpfreechart's Introduction

MPFreeChart

当我们使用 MPAndroidChart 时提示 java.lang.NegativeArraySizeException

问题处理步骤

MPFreeChart 继承自 MPAndroidChart,实现此库的目的是解决MPAndroidChart的LineDataChart的X轴无法添加未排序数据(只能添加递增的x轴数据)的问题 当添加未排序数据到MPAndroidChart时,会报如下错误

    E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.NegativeArraySizeException: -2
            at com.github.mikephil.charting.utils.Transformer.generateTransformedValuesLine(Transformer.java:178)
            at com.github.mikephil.charting.renderer.LineChartRenderer.drawValues(LineChartRenderer.java:567)
            at com.github.mikephil.charting.charts.BarLineChartBase.onDraw(BarLineChartBase.java:297)

用图说话

数据:

        entryList.add(new Entry(0f, -1.56f));
        entryList.add(new Entry(0.1f, -0.33f));
        entryList.add(new Entry(0.2f, 3.68f));
        entryList.add(new Entry(0.3f, 13.15f));
        entryList.add(new Entry(0.4f, 5.11f));
        entryList.add(new Entry(0.5f, 2.98f));
        entryList.add(new Entry(0.6f, 1.84f));
        entryList.add(new Entry(0.5f, 0.93f));
        entryList.add(new Entry(0.4f, -0.43f));
        entryList.add(new Entry(0.3f, -9.02f));
        entryList.add(new Entry(0.2f, -8.78f));
        entryList.add(new Entry(0.1f, -3.63f));
        entryList.add(new Entry(0.0f, -2.27f));

github

Gradle

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of the repositories:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Step 2. Add the dependency

	dependencies {
	        implementation 'com.github.hemingzhong:MPFreeChart:v1.0.4'
	}

Usage

MPFreeChart大多数使用方式和MPAndroidChart相同.

不同点如下

  1. Create the instance object of chart view
    <com.hamz.hfreechart.library.XFreeLineChart
            android:id="@+id/xf_lineChart"
            android:layout_width="match_parent"
            android:layout_height="280dp"/>
  1. 创建XFLineChartManager管理类

  2. 添加点位信息

XFLineChartManager xfLineChartManager = new XFLineChartManager(xFreeLineChart, "电压", Color.CYAN);
        xfLineChartManager.setYAxis(15, -15, 6);
        xfLineChartManager.setDescription("电位仪采集");

        entryList.add(new Entry(0f, -1.56f));
        entryList.add(new Entry(0.1f, -0.33f));
        entryList.add(new Entry(0.2f, 3.68f));
        entryList.add(new Entry(0.3f, 13.15f));
        entryList.add(new Entry(0.4f, 5.11f));
        entryList.add(new Entry(0.5f, 2.98f));
        entryList.add(new Entry(0.6f, 1.84f));
        entryList.add(new Entry(0.5f, 0.93f));
        entryList.add(new Entry(0.4f, -0.43f));
        entryList.add(new Entry(0.3f, -9.02f));
        entryList.add(new Entry(0.2f, -8.78f));
        entryList.add(new Entry(0.1f, -3.63f));
        entryList.add(new Entry(0.0f, -2.27f));
        for (int i = 0; i < entryList.size(); i++) {
            xfLineChartManager.addEntry(entryList.get(i).getX(), entryList.get(i).getY());
        }

mpfreechart's People

Contributors

hemingzhong avatar

Watchers

 avatar

Forkers

ethan-0726

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.