如何在折线图中的高亮点上画一个圆? [英] How can I draw a circle on highlight point in line chart?

查看:181
本文介绍了如何在折线图中的高亮点上画一个圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mpchart绘制图表.我想增加荧光笔和线数据集的交点的圆大小.如何实现呢?

I'm using mpchart to draw my charts.I wanted to increase the circle size of intersection point of highlighter and line dataset. How can I achieve this?

我在某处读到我们可以添加另一个带有突出显示点的数据集并增加其圆的大小.如果我的荧光笔来回拖动并且我不得不非常频繁地更新新的数据集,那真的是一个好方法吗?

I read somewhere that we can add another dataset with highlighted point and increase its circle size. Is that really a good approach if my highlighter will be dragged back and forth and I'll have to update the new dataset very frequently?

推荐答案

使用MpChart库时,该库包含MarkerView类,该类可帮助我们插入用于在图表中显示所选值的标记.我们可以使用MarkerView类显示所选图表数据的任何类型的视图.

When using the MpChart Library, the library contains a MarkerView class that helps us to insert the markers for displaying the selected value in the chart. We can use this MarkerView class to display any kind of view for the selected chart data.

因此,对于该点,我创建了一个新的 ChartMarker 类并扩展了 MarkerView 类.然后在构造函数中,我将包含以点为src的图像视图的布局传递给了super.

So for the dot I created a new ChartMarker class and extended MarkerView class. Then in the constructor I passed the layout containing an image view with the dot as the src to the super.

public ChartMarker(Context context) {
    //the super will take care of displaying the layout
    super(context, R.layout.layout_dot);
}

最后通过chart.setMarkerView()将ChartMarker实例设置为图表

Finally set the ChartMarker instance to the chart through chart.setMarkerView()

ChartMarker elevationMarker = new ChartMarker(getActivity());
elevationChart.setMarkerView(elevationMarker);

对于layout_dot.xml

And for the layout_dot.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

<ImageView
    android:background="@drawable/dot"
    android:layout_width="5dp"
    android:layout_height="5dp" />

</LinearLayout>

这篇关于如何在折线图中的高亮点上画一个圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆