Android Highcharts DialogFragment

Я не знаю, возможно ли это, но я попытался внедрить Chartview из Highchart Android API, чтобы показать линейную диаграмму в 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;
}}

person Neaum    schedule 22.10.2020    source источник
comment
Привет @Neum. Ваша проблема, вероятно, связана с тем, что вы используете старую версию Highcharts для Android. Некоторые проблемы, связанные с динамическим размером диаграммы (например, в DialogFragment), были решены в более поздних версиях.   -  person ppotaczek    schedule 26.10.2020
comment
Привет, хорошо, спасибо за ваш ответ, я попробую с более новой версией!   -  person Neaum    schedule 26.10.2020
comment
@ppotaczek Я использую новую версию, но все еще сталкиваюсь с той же проблемой. Я добавил новый вопрос, можете ли вы его увидеть?   -  person Moeez    schedule 08.05.2021


Ответы (1)


это диалог.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>

Андроид выдает эту ошибку

E/AndroidRuntime: НЕИСПРАВНОЕ ИСКЛЮЧЕНИЕ: основной процесс: com.example.myapplication, PID: 25199 android.view.InflateException: строка двоичного XML-файла №12 в com.example.myapplication:layout/dialog: строка двоичного XML-файла №12 в com .example.myapplication:layout/dialog: Ошибка при завышении класса com.highsoft.highcharts.Core.HIChartView Вызвано: android.view.InflateException: Строка двоичного XML-файла № 12 в com.example.myapplication:layout/dialog: Ошибка при завышении класса com.highsoft.highcharts.Core.HIChartView

и мой код работает, если я добавляю что-то еще, кроме HIChartView, поэтому, если кто-нибудь знает, возможно ли встроить график, это может быть здорово. Спасибо

person Neaum    schedule 22.10.2020
comment
Вам удалось решить эту проблему? - person Moeez; 08.05.2021