如何解决Android Highcharts DialogFragment
我不知道是否可能,但是我尝试从Highchart android API嵌入Chartview,以便在DialogFragment中显示折线图。不幸的是,我没有成功,没有人知道这是否可行,也许可以帮助我做到这一点。 这是我的代码,这是为了获得此对话框片段的测试代码。
ChartDialogFragment.java
public class ChartDialogFragment extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
// Inflate the layout to use as dialog or embedded fragment
View view= inflater.inflate(R.layout.dialog,container,false);
HIChartView chartView =view.findViewById(R.id.hc);
HIOptions options = new HIOptions();
HITitle title = new HITitle();
title.setText("Logarithmic axis demo");
options.setTitle(title);
HIXAxis xaxis = new HIXAxis();
xaxis.setTickInterval(1);
options.setXAxis(new ArrayList<>(Collections.singletonList(xaxis)));
HIYAxis yaxis = new HIYAxis();
yaxis.setType("logarithmic");
yaxis.setMinorTickInterval(0.1);
options.setYAxis(new ArrayList<>(Collections.singletonList(yaxis)));
HITooltip tooltip = new HITooltip();
tooltip.setHeaderFormat("<b>{series.name}</b><br />");
tooltip.setPointFormat("x = {point.x},y = {point.y}");
options.setTooltip(tooltip);
HILine line1 = new HILine();
line1.setPointStart(1);
line1.setData(new ArrayList<>(Arrays.asList(1,2,4,8,16,32,64,128,256,512)));
options.setSeries(new ArrayList<>(Collections.singletonList(line1)));
chartView.setOptions(options);
return view;
}
/** The system calls this only when creating the layout in a dialog. */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return dialog;
}}
解决方法
这是dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="60dp"
android:scaleType="center"
android:background="#FFFFBB33"
android:contentDescription="@string/app_name" />
<com.highsoft.highcharts.Core.HIChartView
android:id="@+id/hc"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Android给我这个错误
E / Android运行时:致命异常:主要 流程:com.example.myapplication,PID:25199 android.view.InflateException:com.example.myapplication:layout / dialog中的二进制XML文件第12行: com.example.myapplication:layout / dialog:膨胀类错误 com.highsoft.highcharts.Core.HIChartView 原因:android.view.InflateException:com.example.myapplication:layout / dialog中的二进制XML文件第12行:膨胀类错误 com.highsoft.highcharts.Core.HIChartView
,如果我放HIChartView以外的任何东西,我的代码就会工作,因此,如果有人知道是否有可能嵌入图形,那可能会很棒。 谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。