mpandroidchart线图标签

发布于 2025-02-12 19:42:39 字数 251 浏览 0 评论 0原文

我想使用mpandroidchart库实现与此类似的效果

我希望将我的标签附加到图表线上,或者至少靠近它。使用此库是可能的吗?还是有行走的?有类似结果的东西

I want to achieve an effect similar to this using the MPAndroidChart library
enter image description here

I want my label to be attached to the Chart line or at least be close to it. Is something like this possible using this library? Or is there a walkaround for this? Something that will have a similar result

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2025-02-19 19:42:39

一种可能的方法是使用标记,Chart.SetMarker(),但是标记仅显示何时在图表上点击何时,如果您希望标记不断显示,则可以调用自定义图表并覆盖像这样的函数绘制标记器,标记在图表的中间绘制:

@Override protected void drawMarkers(Canvas canvas) {
    int j = 0;
    IDataSet set = mData.getDataSetByIndex(j);
    int i = set.getEntryCount() / 3;
    Entry e = set.getEntryForIndex(i);
    Highlight highlight = new Highlight(e.getX(), e.getY(), i);
    highlight.setDataIndex(j);
    // callbacks to update the content
    mMarker.refreshContent(e, highlight);
    MPPointD pix = getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY());
    highlight.setDraw((float)pix.x, (float)pix.y);
    // draw the marker
    float[] pos = getMarkerPosition(highlight);
    mMarker.draw(canvas, pos[0], pos[1]);
}

图片如下所示,黄色标记是标记,它会不断显示,没有用户点击:

7月5日更新

-----在Demo LineChartactivity1 ( https://github.com/philjay/mpandroidchart/blob/master/master/mpchartexample/src/main/main/java/java/java/java/java/xxmassdeveloper/mpcharteveliper/mmpchartexamplivity/linechartexample/linechartacmellive/linechartacmellive1.java ) );设置标记,并通过新的Mymarkerview分配。可以在 https://github.com/philjay/mpandroidchart/blob/master/master/mpchartlib/src/src/main/java/java/java/java/github/github/mikephil/mikephil/charting/charts/linecharts/linechart.java,2.java 定制图表从Linechart延伸

A possible way is to use the marker, chart.setMarker(), but marker only shows when user tap on the chart, if you want the marker to show constantly, an custom chart can be invoked and override the function drawMarkers like this, the marker is drawn in the middle of chart:

@Override protected void drawMarkers(Canvas canvas) {
    int j = 0;
    IDataSet set = mData.getDataSetByIndex(j);
    int i = set.getEntryCount() / 3;
    Entry e = set.getEntryForIndex(i);
    Highlight highlight = new Highlight(e.getX(), e.getY(), i);
    highlight.setDataIndex(j);
    // callbacks to update the content
    mMarker.refreshContent(e, highlight);
    MPPointD pix = getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY());
    highlight.setDraw((float)pix.x, (float)pix.y);
    // draw the marker
    float[] pos = getMarkerPosition(highlight);
    mMarker.draw(canvas, pos[0], pos[1]);
}

Picture as below, the yellow tag is the marker, it is displayed constantly and without a user tap:
enter image description here

----Updated July 5th

In the demo LineChartActivity1(https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java), line 98, chart.setMarker(mv); sets the Marker, and it allocated by new an MyMarkerView. The drawMarkers can be added at https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartLib/src/main/java/com/github/mikephil/charting/charts/LineChart.java, but it's better to use a customed Chart extends from LineChart

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文