如何在Android中使用两套数据使用MPAndroidChart绘制图形

时间:2018-11-21 02:09:53

标签: android charts kotlin mpandroidchart

在尝试使用MPAndroidChart时,我试图使用两组数据

val values1 = ArrayList<Entry>()
values1.add(Entry(3f,2f))
values1.add(Entry(3.5f,4f))
values1.add(Entry(4f,3f))
val values = ArrayList<Entry>()
values.add(Entry(3f,2f))
values.add(Entry(3.5f,4f))
values.add(Entry(4f,3f))
values.add(Entry(4.5f,6f))
values.add(Entry(5f,10f))
values.add(Entry(5.5f,4f))
values.add(Entry(6f,3f))

并绘制折线图

var set1:LineDataSet
var set2:LineDataSet
set1 = LineDataSet(values, "DataSet 1")
set2 = LineDataSet(values1, "DataSet 2")

set1.mode = LineDataSet.Mode.CUBIC_BEZIER
set1.cubicIntensity = 0.2f
set1.setDrawFilled(true)
set1.setDrawCircles(false)
set1.lineWidth = 1.8f
set1.color = ContextCompat.getColor(activity!!, R.color.colorAccent)
set1.fillColor = ContextCompat.getColor(activity!!, R.color.colorAccent)
set1.fillAlpha = 100
set1.setDrawHorizontalHighlightIndicator(false)
//set1.setFillFormatter { dataSet, dataProvider -> chart.axisLeft.minWidth }

set2.mode = LineDataSet.Mode.CUBIC_BEZIER
set2.cubicIntensity = 0.2f
set2.setDrawFilled(true)
set2.setDrawCircles(false)
set2.lineWidth = 1.8f
set2.color = ContextCompat.getColor(activity!!, R.color.colorPrimary)
set2.fillColor = ContextCompat.getColor(activity!!, R.color.colorPrimary)
set2.fillAlpha = 100
set2.setDrawHorizontalHighlightIndicator(false)
//set2.setFillFormatter { dataSet, dataProvider -> chart.axisLeft.zeroLineWidth }

// create a data object with the data sets
val list= mutableListOf<LineDataSet>()
list.add(set1)
list.add(set2)
val data = LineData(list as List<ILineDataSet>?)
data.setValueTextSize(9f)
data.setDrawValues(false)

// set data
chart.data = data

结果是这样的 enter image description here

我只想改善或平滑set2的图形(箭头标记),以使该行与set1完全重叠并隐藏那部分数据。

1 个答案:

答案 0 :(得分:0)

我得到了答案,需要更改模式。

set.mode = LineDataSet.Mode.HORIZONTAL_BEZIER