Java 如何在屏幕上创建显示x轴和y轴值的弹出窗口
如本折线图所示。如何使弹出窗口显示x轴和y轴的值。当我触摸折线图中的节点时,我希望在相应的位置上显示带有相应x轴和y轴值的弹出窗口。就像上面的图片链接一样Java 如何在屏幕上创建显示x轴和y轴值的弹出窗口,java,android,mpandroidchart,Java,Android,Mpandroidchart,如本折线图所示。如何使弹出窗口显示x轴和y轴的值。当我触摸折线图中的节点时,我希望在相应的位置上显示带有相应x轴和y轴值的弹出窗口。就像上面的图片链接一样 final LineChart lineChart = (LineChart) findViewById(R.id.chart); XAxis xl = lineChart.getXAxis(); xl.setPosition(XAxis.XAxisPosition.BOTTOM); ArrayList<Ent
final LineChart lineChart = (LineChart) findViewById(R.id.chart);
XAxis xl = lineChart.getXAxis();
xl.setPosition(XAxis.XAxisPosition.BOTTOM);
ArrayList<Entry> entries = new ArrayList<>();
entries.add(new Entry(4f, 0));
entries.add(new Entry(8f, 1));
entries.add(new Entry(6f, 2));
entries.add(new Entry(2f, 3));
entries.add(new Entry(18f, 4));
entries.add(new Entry(9f, 5));
final LineDataSet dataset = new LineDataSet(entries , "y-axies");
// creating labels
final ArrayList<String> labels = new ArrayList<String>();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
LineData data = new LineData(labels, dataset);
lineChart.setData(data); // set the data and list of lables into chart
lineChart.setDescription("Description"); // set the description
dataset.setDrawCubic(true);
dataset.setDrawFilled(true);
dataset.setHighlightEnabled(true);
lineChart.setTouchEnabled(true);
dataset.setColors(ColorTemplate.COLORFUL_COLORS);
lineChart.animateY(5000);
final LineChart LineChart=(LineChart)findviewbyd(R.id.chart);
XAxis xl=lineChart.getXAxis();
xl.setPosition(XAxis.XAxisPosition.BOTTOM);
ArrayList条目=新的ArrayList();
条目。添加(新条目(4f,0));
增加(新条目(8f,1));
增加(新条目(6f,2));
添加(新条目(2f,3));
增加(新条目(18f,4));
增加(新条目(9f,5));
最终LineDataSet数据集=新的LineDataSet(条目“y轴”);
//创建标签
最终ArrayList标签=新ArrayList();
标签。添加(“一月”);
标签。添加(“二月”);
标签。添加(“三月”);
标签。添加(“四月”);
标签。添加(“可能”);
标签。添加(“六月”);
LineData数据=新的LineData(标签、数据集);
线形图.设置数据(数据);//将数据和标签列表设置为图表
lineChart.setDescription(“Description”);//设置描述
dataset.setDrawCubic(true);
dataset.setDrawFilled(true);
dataset.SetHighlightabled(真);
lineChart.setTouchEnabled(真);
setColors(ColorTemplate.colorial_COLORS);
animateY线条图(5000);
如果使用MPAndroidChart库,则可以使用本机MarkerView类实现这一点。您可以在Github托管项目的wiki中找到说明
编辑:
我补充了一些信息,我们如何才能做到这一点:
1.您必须实现MarkerView类,该类支持在图表上绘制弹出窗口。示例类:
public class CustomMarkerView extends MarkerView {
private TextView tvContent;
public CustomMarkerView (Context context, int layoutResource) {
super(context, layoutResource);
// this markerview only displays a textview
tvContent = (TextView) findViewById(R.id.tvContent);
}
// callbacks everytime the MarkerView is redrawn, can be used to update the
// content (user-interface)
@Override
public void refreshContent(Entry e, Highlight highlight) {
tvContent.setText("" + e.getVal()); // set the entry-value as the display text
}
@Override
public int getXOffset(float xpos) {
// this will center the marker-view horizontally
return -(getWidth() / 2);
}
@Override
public int getYOffset(float ypos) {
// this will cause the marker-view to be above the selected value
return -getHeight();
}
二,。若你们有这个,接下来你们必须用弹出窗口的布局定义xml文件。xml示例:
CustomMarkerView mv=新的CustomMarkerView(上下文,R.layout.custom\u marker\u view\u布局);
图.setMarkerView(mv)代码>
之后,您的图表上会出现功能齐全的弹出窗口。链接到包含更多信息的网站:如果您使用MPAndroidChart库,则可以使用本机MarkerView类实现此功能。您可以在Github托管项目的wiki中找到说明
编辑:
我补充了一些信息,我们如何才能做到这一点:
1.您必须实现MarkerView类,该类支持在图表上绘制弹出窗口。示例类:
public class CustomMarkerView extends MarkerView {
private TextView tvContent;
public CustomMarkerView (Context context, int layoutResource) {
super(context, layoutResource);
// this markerview only displays a textview
tvContent = (TextView) findViewById(R.id.tvContent);
}
// callbacks everytime the MarkerView is redrawn, can be used to update the
// content (user-interface)
@Override
public void refreshContent(Entry e, Highlight highlight) {
tvContent.setText("" + e.getVal()); // set the entry-value as the display text
}
@Override
public int getXOffset(float xpos) {
// this will center the marker-view horizontally
return -(getWidth() / 2);
}
@Override
public int getYOffset(float ypos) {
// this will cause the marker-view to be above the selected value
return -getHeight();
}
二,。若你们有这个,接下来你们必须用弹出窗口的布局定义xml文件。xml示例:
之后,只能将自定义类附加到chartView:
CustomMarkerView mv=新的CustomMarkerView(上下文,R.layout.custom\u marker\u view\u布局);
图.setMarkerView(mv)代码>
之后,您的图表上会出现功能齐全的弹出窗口。链接到网站,了解更多信息:您面临什么问题…欢迎来到SOF亲爱的@你想在弹出窗口中显示折线图吗???你面临什么问题…欢迎来到SOF亲爱的@Bhagya Shria您想在弹出窗口中显示折线图吗???虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能无效。-正如您所建议的,我添加了实现示例。不要投反对票。虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能无效。-正如您所建议的,我添加了实现示例。不要投反对票。