MPAndroidChart:在同一高光处有多个标记

MPAndroidChart:在同一高光处有多个标记,android,mpandroidchart,Android,Mpandroidchart,我想在单击时显示三个工具提示/标记,其中只有一个数据集 如下图所示: 我怎么做呢?我已经创建了一个折线图,并将数据提供给它。 对于多个标记,我创建了一个实现IMarker的类,并创建了2个对象 我为每个标记的信息制作了一个类。 第二个标记的显示方式取决于第一个标记的位置。 我知道这可能不是一个很好的实现,但是很有效 以下是对我有用的代码: public class ImageMakerTwoINOne implements IMarker { private Context mCont

我想在单击时显示三个
工具提示/标记
,其中只有一个
数据集

如下图所示:


我怎么做呢?

我已经创建了一个
折线图
,并将数据提供给它。 对于多个标记,我创建了一个实现IMarker的类,并创建了2个对象 我为每个标记的信息制作了一个类。 第二个标记的显示方式取决于第一个标记的位置。 我知道这可能不是一个很好的实现,但是很有效

以下是对我有用的代码:

public class ImageMakerTwoINOne implements IMarker {
    private Context mContext;
    public static final String TAG = "marker class";

    ObjectImage o1 = new ObjectImage();
    ObjectImage o2 = new ObjectImage();

    //constructor for initialization
    public ImageMakerTwoINOne(Context context, int drawableResourceId,int drawableResourceId2) {
        mContext = context;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            o1.drawable = mContext.getResources().getDrawable(drawableResourceId, null);
            o2.drawable = mContext.getResources().getDrawable(drawableResourceId2,null);
        } else {
             o1.drawable = mContext.getResources().getDrawable(drawableResourceId);
             o2.drawable = mContext.getResources().getDrawable(drawableResourceId2);
         }
    }


//////////////////////////////offset////////////////////////////
//setting the offsets by the users
public void setOffset(MPPointF offset,MPPointF offset2) {
    o1.offset = offset;
    o2.offset = offset2;
    //in case they were null :
    if (offset == null) o1.offset = new MPPointF();
    else if (offset2 == null) o2.offset = new MPPointF();
}
//setting the offsets by the user
public void setOffset(float offsetX, float offsetY , float offsetX2 , float offsetY2) {
    o1.offset.x = offsetX;
    o1.offset.y = offsetY;
    o2.offset.x = offsetX2;
    o2.offset.y = offsetY2;
}

@Override
public MPPointF getOffset() { return o2.offset; }

public MPPointF getOffset2(){ return o2.offset; }
////////////////////////size//////////////////////////////
//setting the size by the user
public void setSize(FSize size , FSize size2) {
    o1.size = size;
    o2.size = size2;
}
//getting the size of the objects
public FSize getSize1() { return o1.size; }
public FSize getSize2() { return o2.size; }
//////////////////chart///////////////////////////////////
//setting the charts
public void setChartView(Chart chart,Chart chart2) {
    o1.weakChart = new WeakReference<>(chart);
    o2.weakChart = new WeakReference<>(chart2);
}
//getting chart
public Chart getChartView1() {return o1.weakChart == null ? null : o1.weakChart.get(); }
public Chart getChartView2() { return o2.weakChart == null ? null : o2.weakChart.get(); }

//getting offset
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {
    MPPointF offset = getOffset();
    Chart chart = getChartView1();

    float width1 = o1.size.width;
    float height1 = o1.size.height;
    if (width1==0.f){ width1 = o1.drawable.getIntrinsicWidth(); }
    if (height1==0.f){ height1 = o1.drawable.getIntrinsicHeight(); }
    MPPointF alaki = getOffsetForDrawingAtPoint2(posX,posY);
    return o1.offset;
}
public MPPointF getOffsetForDrawingAtPoint2(float posx , float posY){
    MPPointF offset = getOffset();
    Chart chart = getChartView1();

    float width1 = o2.size.width;
    float height1 = o2.size.height;
    if (width1==0.f){ width1 = o2.drawable.getIntrinsicWidth(); }
    if (height1==0.f){ height1 = o2.drawable.getIntrinsicHeight(); }
    return o2.offset;
}

@Override
public void refreshContent(Entry e, Highlight highlight) {

}

     @Override
     public void draw(Canvas canvas, float posX, float posY) {
        Canvas canvas2 = canvas;
        if (o1.drawable == null) return;
        MPPointF offset = getOffsetForDrawingAtPoint(posX,posY); //main position
        MPPointF offset2 = o2.offset; //main position obj 2
        float width = o1.size.width;
        float height = o1.size.height;
        if (width == 0.f) { width = o1.drawable.getIntrinsicWidth(); }
        if (height == 0.f) { height = o1.drawable.getIntrinsicHeight();}

        float width2 = 128;//o2.size.width;
        float height2 = 129;//o2.size.height;
        if (width == 0.f) { width = o2.drawable.getIntrinsicWidth(); }
        if (height == 0.f) { height = o2.drawable.getIntrinsicHeight();}

        o1.drawable.copyBounds(o1.drawableBoundsCache);
        o1.drawable.setBounds(
            o1.drawableBoundsCache.left,
            o1.drawableBoundsCache.top,
            (int) (o1.drawableBoundsCache.left+width),
            (int) (o1.drawableBoundsCache.top+height)
        );

        o2.drawable.copyBounds(o2.drawableBoundsCache);
        o2.drawable.setBounds(
            o2.drawableBoundsCache.left,
            o2.drawableBoundsCache.top,
            (int) (o2.drawableBoundsCache.left+width2),
            (int) (o2.drawableBoundsCache.top+height2)
        );

        int saveId = canvas.save();
        int saveId2 = canvas2.save();
    
        canvas.translate(posX + offset.x , posY + offset.y);
        o1.drawable.draw(canvas);
        canvas2.translate( 75 , -45 );

        o2.drawable.draw(canvas2);

        canvas2.restoreToCount(saveId2);
        canvas.restoreToCount(saveId);

        o1.drawable.setBounds(o1.drawableBoundsCache);
        o2.drawable.setBounds(o2.drawableBoundsCache);
    }
}


public class ObjectImage {
    public Drawable drawable;
    public MPPointF offset = new MPPointF();
    public WeakReference<Chart> weakChart;
    public FSize size = new FSize();
    public Rect drawableBoundsCache = new Rect();
}
公共类ImageMakerTwoINOne实现IMarker{
私有上下文;
公共静态最终字符串TAG=“marker class”;
ObjectImage o1=新ObjectImage();
ObjectImage o2=新ObjectImage();
//用于初始化的构造函数
公共ImageMakerTwoINOne(上下文上下文,int-drawableResourceId,int-drawableResourceId2){
mContext=上下文;
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.LOLLIPOP){
o1.drawable=mContext.getResources().getDrawable(drawableResourceId,null);
o2.drawable=mContext.getResources().getDrawable(drawableResourceId2,null);
}否则{
o1.drawable=mContext.getResources().getDrawable(drawableResourceId);
o2.drawable=mContext.getResources().getDrawable(drawableResourceId2);
}
}
//////////////////////////////抵消////////////////////////////
//由用户设置偏移
公共void setOffset(MPPointF offset,MPPointF offset 2){
o1.offset=偏移量;
o2.offset=offset2;
//如果它们为空:
如果(offset==null)o1.offset=new MPPointF();
如果(offset2==null)o2.offset=new MPPointF(),则为else;
}
//由用户设置偏移
公共void setOffset(float offsetX、float offsetX、float offsetX2、float offset2){
o1.offset.x=offset x;
o1.offset.y=offset;
o2.偏移量.x=偏移量x2;
o2.offset.y=offset2;
}
@凌驾
公共MPPointF getOffset(){return o2.offset;}
公共MPPointF getOffset2(){return o2.offset;}
////////////////////////大小//////////////////////////////
//由用户设置大小
公共void setSize(FSize size,fsize2){
o1.尺寸=尺寸;
o2.size=尺寸2;
}
//获取对象的大小
public FSize getSize1(){return o1.size;}
public FSize getSize2(){return o2.size;}
//////////////////图表///////////////////////////////////
//设置图表
公共无效设置图表视图(图表、图表2){
o1.weakChart=新的WeakReference(图表);
o2.weakChart=新WeakReference(图表2);
}
//获取图表
公共图表getChartView1(){return o1.weakChart==null?null:o1.weakChart.get();}
公共图表getChartView2(){返回o2.weakChart==null?null:o2.weakChart.get();}
//抵消
@凌驾
公共MPPointF getOffsetForDrawingAtPoint(浮点posX,浮点posY){
MPPointF offset=getOffset();
Chart Chart=getChartView1();
浮动宽度1=o1.size.width;
浮动高度1=o1.size.height;
如果(width1==0.f){width1=o1.drawable.getIntrinsicWidth();}
如果(height1==0.f){height1=o1.drawable.getIntrinsicHeight();}
MPPointF alaki=getOffsetForDrawingAtPoint2(posX,posY);
返回o1.0偏移量;
}
公共MPPointF getOffsetForDrawingAtPoint2(浮点posx,浮点posY){
MPPointF offset=getOffset();
Chart Chart=getChartView1();
浮子宽度1=o2.size.width;
浮子高度1=o2.size.height;
如果(width1==0.f){width1=o2.drawable.getIntrinsicWidth();}
如果(height1==0.f){height1=o2.drawable.getIntrinsicHeight();}
返回o2.offset;
}
@凌驾
公共内容(条目e,突出显示){
}
@凌驾
公共虚空绘制(画布、浮标posX、浮标posY){
画布画布2=画布;
if(o1.drawable==null)返回;
MPPointF offset=GetOffsetForDrawingAttpoint(posX,posY);//主位置
MPPointF offset2=o2.offset;//主位置obj 2
浮动宽度=o1.size.width;
浮动高度=o1.size.height;
如果(width==0.f){width=o1.drawable.getIntrinsicWidth();}
如果(height==0.f){height=o1.drawable.getIntrinsicHeight();}
浮动宽度2=128;//o2.size.width;
浮动高度2=129;//o2.size.height;
如果(width==0.f){width=o2.drawable.getIntrinsicWidth();}
如果(height==0.f){height=o2.drawable.getIntrinsicHeight();}
o1.可绘制的.复制边界(o1.可绘制的边界缓存);
o1.可拉深的立根(
o1.drawableBoundsCache.left,
o1.drawableBoundsCache.top,
(内部)(o1.可绘制边界草图左+宽),
(内部)(o1.可绘制边界草图顶部+高度)
);
o2.drawable.copyBounds(o2.drawableBoundsCache);
o2.可拉深的.立根(
o2.drawableBoundsCache.左,
o2.drawableBoundsCache.top,
(内部)(o2.可绘制边界草图左+宽度2),
(内部)(o2.可拉伸边界顶部+高度2)
);
int saveId=canvas.save();
int saveId2=canvas2.save();
canvas.translate(posX+offset.x,posY+offset.y);
o1.可绘制。绘制(画布);
游说2.翻译(75,-45);
o2.可绘制。绘制(画布2);
canvas2.恢复计数(saveId2);
canvas.restoreToCount(saveId);
o1.可拉深的立根(o1.可拉深的边界);
o2.可拉深缩边(o2.可拉深边界);
}
}
公共类对象映像{
公众可支取;
公共MPPointF偏移量=新MPPointF();
公共福利费;福利费;
public FSize size=new FSize();
public Rect drawablebundscache=new Rect();
}

也许这个答案可以解决您的问题谢谢您的回答,但这不是我想要的答案,我想知道的是如何使用pnly一个数据集显示trhee标签(一个在X轴上,一个在X轴上