我正在使用MPAndroidChart,想知道如何在以下图表上执行点击事件并获取相关的回调: 饼图:点击特定原因打开其详细信息。 条形图:点击任意栏打开其详细信息。 堆积条形图:点击任意栏打开其详细信息。
我需要在点击图表时收到通知。
答案 0 :(得分:8)
使用override func shouldAutorotate() -> Bool {
return false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientation.Portrait.rawValue
}
。您可以找到有关如何实施它的文档here。
此侦听器允许您对图表上执行的单击手势做出反应。
答案 1 :(得分:4)
for LineChart
chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener()
{
@Override
public void onValueSelected(Entry e, Highlight h)
{
float x=e.getX();
float y=e.getY();
}
@Override
public void onNothingSelected()
{
}
});
答案 2 :(得分:2)
对于LineChart,如果您在Kotlin中使用显示的非浮点值,请使用以下代码
lineChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener
{
override fun onValueSelected(e: Entry, h: Highlight?) {
val x = e.x.toString()
val y = e.y
val selectedXAxisCount = x.substringBefore(".") //this value is float so use substringbefore method
// another method shown below
val nonFloat=lineChart.getXAxis().getValueFormatter().getFormattedValue(e.x)
//if you are display any string in x axis you will get this
}
override fun onNothingSelected() {}
})
快乐的编码...
答案 3 :(得分:1)
For PieChart :-
mPieChart.setOnChartValueSelectedListener(object :
OnChartValueSelectedListener {
override fun onNothingSelected() {
}
override fun onValueSelected(e: Entry?, h: Highlight?) {
val pieEntry = e as PieEntry
val label: String = pieEntry.label
}
})
答案 4 :(得分:0)
[HtmlTargetElement("widget", Attributes = WidgetNameAttributeName)]
public class WidgetTagHelper : TagHelper
{
private readonly IViewComponentHelper _viewComponentHelper;
public WidgetTagHelper(IViewComponentHelper viewComponentHelper)
{
_viewComponentHelper = viewComponentHelper;
}
.....
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
((IViewContextAware)_viewComponentHelper).Contextualize(ViewContext);
var content = await _viewComponentHelper.InvokeAsync(typeof(FreeTextViewComponent), new { ftxCode = FTXCode, objRef = OBJRef, customPara = CustomPara });
output.Content.SetHtmlContent(content);
}
}
这是在科特林
OnChartValueSelectedListener
答案 5 :(得分:0)
OnChartValueSelectedListener
@Override
public void onValueSelected(Entry e, Highlight h) {
// enter your code here
}
@Override
public void onNothingSelected() {
// do nothing
}
chart.setOnChartValueSelectedListener(this);