- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最佳答案
我创建了一个 LineChart
并给它数据。
对于多个标记,我创建了一个实现 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();
}
关于android - MPAndroidChart:同一突出显示的多个标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49818035/
我正在做一个项目,最近开始使用 MPAndroidChart。 我让 MPAndroidChart 正常工作并正确填充图表数据,但我想要一种能够拖动和选择图表区域的方法。选择完成后,它需要返回所选点的
我知道删除x值的方法,但是我如何删除y值。我基本上不希望饼图上有任何文本。 该图显示了饼图顶部带有80.0和20.0标签的当前状态。 最佳答案 删除Y值 使用dataset.setDrawValues
在我的应用程序中,我使用 ios-charts 库(MPAndroidChart 的快速替代品)。我需要的只是显示带有日期和值的折线图。 现在我使用这个函数来显示图表 func setChart(da
我正在使用这个很棒的绘图仪框架 ios-charts。 Android 版本的文档指出,可以使用“setTouchEnabled(false)”禁用图表上的触摸事件。但是我在 iOS 版本中找不到此功
我正在使用 MPAndroidChart (v3.0.2) 在我的 Android 应用程序中实时绘制我的数据。我需要平滑图表的线条(来自传感器的噪音)。我了解我需要使用以下任何一种方法: lineD
我正在尝试使用 MpAndroidChart 库绘制圆角饼图。 预期输出与此类似。 两端都需要外圆。有一个方法 pieChart.setDrawRoundedSlices(true),但问题是饼图的起
那么如何只渲染 x 轴而不渲染其上的网格线。从附图中可以看出,我将轴线的宽度设置为 4 ,将网格线的宽度设置为 2 。所以黑线出现在白轴线上。我只想显示轴线。我该怎么做。 最佳答案 正如 docs 中
我想在轴的末端放置一个箭头,但我不知道如何在 MPAndroidCharts 库中实现这一点。最后应该是这样的。 我目前的风格: val xAxis = chart.xAxis xAxis.s
在 CombinedChart 中添加 chart.setFitBars(true) 将使第一个和最后一个条可见。 我需要做同样的事情来组合折线图和条形图。 现在,第一个和最后一个条不完全可见。 我试
我想点击显示,三个tooltips/markers , 只有一个 dataset . 如下图所示: 我该怎么做? 最佳答案 我创建了一个 LineChart并给它数据。 对于多个标记,我创建了一个实现
有没有办法让 MarkerView 固定位置?我需要在 修复它左上或 右上角角落。 最佳答案 这是将标记固定在左上角或右上角的一种方法 创建自定义 MarkerView 后,您可以执行以下操作。 1)
我使用 MPAndroidChart 制作了 LineChart 并将 x 轴文本大小设置为 15。不幸的是,由于文本大小较大,x 轴标签在顶部被截断: 我怎么解决这个问题? 最佳答案 chart.e
我在Android Studio中将Kotlin与MPAndroidChart结合使用。我设法从示例中构建标准图表,但是我需要一些不同的东西。 是否可以在条形图包含间隙的地方构建水平条形图? 类似于以
我想更改限制线顶部图表的颜色。我们现在已经实现了更改跨越限制线的图表条的颜色。但我想做的是改变图表跨越限制线的颜色。 最佳答案 我假设您在此处使用BarChart 事实证明this response正
我读过各种教程,但大多数都展示了相同的示例。图例数组放入以下构造函数中: new PieData(legendValues, IPieDataSet dataSet) 但是 PieData 没有这个构
这是我的饼图,我想将这些数据移动到我想要的位置,那么我该怎么做呢? protected void onCreate(Bundle savedInstanceState) { super.onC
example 我已经尝试过了。请帮助我..我真的不知道。我认为这与 Canvas 类有关。 自定义线图渲染器 我觉得颜色不是根据x值填充的,而是一次性填充的。 这很难,因为我不习惯 Canvas 。
我正在使用“implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'”这个库来创建饼图,并且我手动输入的饼图条目值显示不正确。我按照教程进行操
在MpAndroidChart中使用饼图时,成功绘制了饼图。当尝试向图表图例添加自定义标签和颜色时。标签正在更新,但所有图例的图例颜色均为蓝色。 ArrayList PieEntryLabels
这是条形图的图片。正如您所看到的,存在对齐问题,条形图未与标签对齐,特别是在中间部分。另外,我希望底部轴显示 10 的条形,而不是 1.2、1.4、1.6 等,因为永远不会有任何小数,所以它没有用。我
我是一名优秀的程序员,十分优秀!