2

I don't know if it is possible but I tried to Embedded a Chartview from Highchart android API in order to show a line chart in a DialogFragment. Unfortunately, I didn't succeed anyone knows if it's possible and maybe Help me to do it. Here's my code this is a test code in order to get this dialog fragment.

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;
}}
Neaum
  • 21
  • 1
  • Hi @Neaum, Your problem probably results from the fact that you use old Highcharts Android version. Some problems related with dynamic chart size (like in DialogFragment) were resolved in later versions. – ppotaczek Oct 26 '20 at 08:55
  • Hi, ok thanks for your answer I'll try with a newer version! – Neaum Oct 26 '20 at 12:05
  • @ppotaczek I am using new version but still facing the same issue I added a new [question](https://stackoverflow.com/q/67446196/6854117) can you please see it ? – Moeez May 08 '21 at 10:52

1 Answers1

0

this is 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 gives me this error

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.myapplication, PID: 25199 android.view.InflateException: Binary XML file line #12 in com.example.myapplication:layout/dialog: Binary XML file line #12 in com.example.myapplication:layout/dialog: Error inflating class com.highsoft.highcharts.Core.HIChartView Caused by: android.view.InflateException: Binary XML file line #12 in com.example.myapplication:layout/dialog: Error inflating class com.highsoft.highcharts.Core.HIChartView

and my code work if I put anything else than HIChartView so if anyone know if It's possible to get the graph embedded it could be great. Thanks

Neaum
  • 21
  • 1