Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report