Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method of dynamically adding data and stacking line charts with Android?

Shulou Source: shulou.com Published: 2022-06-02 20:26:48 09月19日 Update

This article introduces the relevant knowledge of "what is the method of dynamically adding data and stacking line charts by Android". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Effect video

Reference description

This example uses a third-party SDK--helloCharts that is very, very useful.

Portal

Guide package

Step 1: import maven

Maven {url 'https://jitpack.io'}

Step 2: import dependencies

Implementation 'com.github.lecho:hellocharts-library:1.5.8@aar' Code Analysis

A total of three broken lines are used in this example, namely, temperature, humidity and light.

Initialization

Initialize three broken line colors

TmpLine = new Line (mTmpChart). SetColor (Color.parseColor ("# cc00ff")); HumLine= new Line (mHumChart). SetColor (Color.parseColor ("# 0033ff")); LightLine = new Line (mLightChart). SetColor (Color.parseColor ("# cc0000"))

Initialize three broken line styl

TmpLine.setShape (ValueShape.SQUARE); TmpLine.setCubic (true); / / whether the curve is smooth, that is, curve or broken line TmpLine.setFilled (true); / / whether to fill the area of the curve TmpLine.setHasLabels (true); / / whether to add remarks TmpLine.setHasLines (true) to the data coordinates of the curve; / / whether to display with lines. If false, there is no curve and only point display TmpLine.setHasPoints (true); / / whether to display the dot if it is false, there is no origin, only point display (each data point is a large dot) HumLine.setShape (ValueShape.CIRCLE); / / the shape of each data point on the line chart is circular (there are three kinds: ValueShape.SQUARE ValueShape.CIRCLE ValueShape.DIAMOND) HumLine.setCubic (true) / / whether the curve is smooth, that is, whether the curve or broken line HumLine.setFilled (true); / / whether to fill the area of the curve HumLine.setHasLabels (true); / / whether to add remarks HumLine.setHasLines (true) to the data coordinates of the curve; / / whether to display it with lines. If false, there is no curve and only point display HumLine.setHasPoints (true); / / whether to display the dot if it is false, there is no origin, only point display (each data point is a large dot) LightLine.setShape (ValueShape.DIAMOND); / / the shape of each data point on the line chart is circular (there are three kinds: ValueShape.SQUARE ValueShape.CIRCLE ValueShape.DIAMOND) LightLine.setCubic (true) / / whether the curve is smooth, that is, whether the curve or broken line LightLine.setFilled (true); / / whether to fill the area of the curve LightLine.setHasLabels (true); / / whether to add remarks LightLine.setHasLines (true) to the data coordinates of the curve; / / whether to display it with lines. If false, there is no curve and only points display LightLine.setHasPoints (true); / / whether to display dots if false, there is no origin and only points are displayed (each data point is a large dot)

Add three broken lines to the broken line collection

Lines.add (TmpLine); lines.add (HumLine); lines.add (LightLine)

Add a broken line

Data = new LineChartData (); data.setLines (lines)

Initialize X axis, Y axis style attribut

Axis axisX = new Axis (); / / X axis axisX.setHasTiltedLabels (false); / / X axis font is oblique or straight, true is oblique display axisX.setTextColor (Color.RED); / / set font color / / axisX.setName ("time"); / / Table name axisX.setTextSize (7); / / set font size axisX.setMaxLabelChars (10) / / A few X-axis coordinates at most, which means that your scaling makes the number of data on the X-axis 7.

Tags: Data curves coordinates broken lines fonts only dots dynamics line graphs size position time or name three method smoothing number origin remarks Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Docker OPPO Reno Linux MariaDB