GithubHelp home page GithubHelp logo

kiba1215 / coordinateaxischart Goto Github PK

View Code? Open in Web Editor NEW
45.0 4.0 11.0 661 KB

A simple Math coordinate system on Android. 绘制坐标轴 函数图像

License: Apache License 2.0

Java 100.00%
coordinate chart coordinate-systems axischart android-coordiante-system

coordinateaxischart's Introduction

CoordinateAxisChart

  • A simple Math coordinate system in Android.
  • Using this library to draw function lines and points to a coordinate system.

ScreenShot

screenshot

Supported functions

function name description
linear function (一次函数) y = a * x + b
power function (幂函数) y = a * x ^c + b
exponential function (指数函数) y = a * c^x + b
logarithmic function (对数函数) y = a * log(c * x + d) + b
circular function (三角函数) y = a * sin(c * x + d) + b, also cos(), tan(), cot()
tan( ) and cot( ) is still under optimizing.

iOS version entrance

CoordinateAxisChart For iOS

Gradle

repositories {
    jcenter()
}

Add the following dependency to build.gradle:

dependencies {
	compile 'com.kiba:CoordinateAxisChart:1.0.0'
}

Usage

Setup

<com.kiba.coordinateaxischart.CoordinateAxisChart
        android:id="@+id/coordinateAxisChart"
        android:layout_width="300dp"
        android:layout_height="300dp"/>
coordinateAxisChart = (CoordinateAxisChart) findViewById(R.id.coordinateAxisChart);
ChartConfig config = new ChartConfig();

// the max value of the axis 坐标轴的最大值
config.setMax(12);

/* 
    The precision of tangent lines of the points on the function line 
    recommended value: 1-10 
    函数图像上的点的切线的精度 推荐值:1-10
*/
config.setPrecision(1); 

/*
    The x axis will be equally separated to some segment points according to segmentSize
    and will connect these points when drawing the function.
    将x轴分割成segmentSize个点,成像时会将这些点连接起来。
*/
config.setSegmentSize(50);

coordinateAxisChart.setConfig(config);

Add a function line

// linear----LinearType(a, b)
FunctionLine<LinearType> line1 = new FunctionLine<>(new LinearType(2, 1), Color.parseColor("#43A047"));
coordinateAxisChart.addFunctionLine(line1);

// power----PowerType(a, b, c)
FunctionLine<PowerType> line2 = new FunctionLine<>(new PowerType(1, 0, 2), Color.parseColor("#e53935"));
coordinateAxisChart.addFunctionLine(line2);

// log----LogType(a, b, c, d)
FunctionLine<LogType> line3 = new FunctionLine<>(new LogType(1, 0, 1, 0), Color.parseColor("#757575"));
coordinateAxisChart.addFunctionLine(line3);

// sin (circular)----CircularType(a, b, c, d, CircularType.Circular)
FunctionLine<CircularType> line4 = new FunctionLine<>(
    	new CircularType(1, 0, 1, 0, CircularType.Circular.SIN), Color.parseColor("#FFCA28"));
coordinateAxisChart.addFunctionLine(line4);

// exp----ExpType(a, b, c)
FunctionLine<ExpType> line5 = new FunctionLine<>(new ExpType(1, 0, 2), Color.parseColor("#00B0FF"));
coordinateAxisChart.addFunctionLine(line5);

coordinateAxisChart.invalidate();

Add a point

SinglePoint point = new SinglePoint(new PointF(1f, 2f));
point.setPointColor(Color.RED);
coordinateAxisChart.addPoint(point);
coordinateAxisChart.invalidate();

Reset

coordinateAxisChart.reset();
coordinateAxisChart.invalidate();

coordinateaxischart's People

Contributors

kiba1215 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

coordinateaxischart's Issues

关于幂函数的指数不是整数时图像不显示问题

当幂函数的指数不是整数时,图像是出不来的,比如 y = x^2.1 ,这是因为Math.pow(a,b);这个函数不支持 a<0且b不是整数的情况,此种情况会导致 domain error 错误。而程序会生成 x 小于0的点和 x 大于 0的点,当 x 小于0 求 y值时,所得y = NaN,故导致函数点无法绘制,函数图像绘制失败。请知悉。
我的解决办法是 当指数不是整数时,不生成x < 0的点,这样导致函数只有x>0的部分,但不会报错不显示。

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.