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以外的任何东西,我的代码就会工作,因此,如果有人知道是否有可能嵌入图形,那可能会很棒。 谢谢