I'm creating charts (HIChartView) DialogFragment, and then I add them with addView() inside a scrollable LinearLayout dynamically, depending on how many graphs need to be plotted. My main issue is that there are times where graphs simply wont be there, but if I close the dialog and reopen it, they will be there, and might some other graph disappear. And there are times where everything shows up as expected.
This seems to happen at random.
Here is some examples of how the charts are initialized as Views and getting ready to be configured:
Code: Select all
final View chartLayoutView = getLayoutInflater().from(getContext()).inflate(R.layout.chart_constraint_layout, linearLayout, false);
HIChartView chartView = (HIChartView) chartLayoutView.findViewById(R.id.chart);
linearLayout.addView(chartLayoutView, dynamicPos);//if there are already graphs inside linearLayout and it is required for the graph to be in specific order, //otherwise dynamicPos wont be used as parameter when I use addView.
Code: Select all
public static void initializeChart(HIChartView hiChartView, ArrayList<Float> maxMinArrayList, ArrayList<HIXAxis> hixAxisList,
Map<String, Double> chartPlotLines, ArrayList<HIPlotBands> plotBands, ArrayList<Number> tickPositions,
ArrayList<HISeries> hiSeriesList, Map<String, String> chartTexts) {
if (hiChartView.getOptions() == null) {
HIOptions options = new HIOptions();
HIChart chart = new HIChart();
chart.setZoomType("xy");
chart.setMarginRight(10);
chart.setMarginLeft(10);
options.setChart(chart);
HICredits credits = new HICredits();
credits.setEnabled(false);
options.setCredits(credits);
HIExporting hiExporting = new HIExporting();
hiExporting.setEnabled(false);
options.setExporting(hiExporting);
HITitle title = new HITitle();
title.setText("");
options.setTitle(title);
options.setXAxis(hixAxisList);
options.setYAxis(initializeSingleTrendingYAxis(maxMinArrayList, chartPlotLines, plotBands, tickPositions, chartTexts.get("ChartSideTitle"), chartTexts.get("isInfinitePlotBands"), chartTexts));
HITooltip tooltip = new HITooltip();
//......configuration of tooltip
options.setTooltip(tooltip);
HILegend legend = new HILegend();
//......configuration of legend
hiSeriesList.addAll(createLegendLines());//... passing some parameters it returns an ArrayList of HILine type
options.setLegend(legend);
options.setSeries(hiSeriesList);
hiChartView.setOptions(options);
hiChartView.update(options, true, true);
} else {
updateTrending(hiChartView, maxMinArrayList, hiSeriesList, graphPlotLines, plotBands, tickPositions, graphTexts);
}
}
Code: Select all
public static ArrayList<HIYAxis> initializeSingleTrendingYAxis(ArrayList<Float> maxMinArrayList, Map<String, Double> plotLines,
ArrayList<HIPlotBands> plotBands, ArrayList<Number> tickPositions, String title, Map<String, String> graphTexts) {
ArrayList<HIPlotLines> plotLines = new ArrayList<>();
HIYAxis yaxis = new HIYAxis();
yaxis.setTitle(new HITitle());
yaxis.getTitle().setText(title);
yaxis.getTitle().setRotation(0);
yaxis.getTitle().setOffset(40);
yaxis.getTitle().setY(-20);
yaxis.getTitle().setAlign("high");
yaxis.getTitle().setStyle(new HICSSObject());
yaxis.getTitle().getStyle().setColor("2E3040");
yaxis.getTitle().getStyle().setFontSize("13");
yaxis.getTitle().setTextAlign("left");
yaxis.setLineWidth(2);
yaxis.setLineColor(HIColor.initWithHexValue("E6E6E6"));
yaxis.setTickColor(HIColor.initWithHexValue("E6E6E6"));
yaxis.setVisible(true);
float maxValue;
float minValue;
if (!maxMinArrayList.isEmpty()) {
maxValue = maxMinArrayList.get(1);
minValue= maxMinArrayList.get(0);
yaxis.setPlotBands(createPlotBandsRange(maxMinArrayList.get(1), maxMinArrayList.get(0), plotBands, isInfinitePlotBands));
if (null != tickPositions && !tickPositions.isEmpty()) {
yaxis.setTickPositions(tickPositions);
yaxis.setEndOnTick(false);
}
yaxis.setSoftMin(minValue);
yaxis.setSoftMax(maxValue);
}
yaxis.setStartOnTick(false);
yaxis.setGridLineWidth(1);
yaxis.setGridLineColor(HIColor.initWithHexValue("D9DADB"));
HILabels labels = new HILabels();
//....configuration of labels
yaxis.setLabels(labels);
yaxis.setMinorGridLineWidth(0);
yaxis.setMinorTickInterval(0.5);
yaxis.setMinorTickLength(5);
yaxis.setMinorTickWidth(1);
yaxis.setMinorTickColor(HIColor.initWithHexValue("ffffff"));
HICrosshair crosshair = new HICrosshair();
crosshair.setWidth(3);
yaxis.setCrosshair(crosshair);
plotLines.addAll(addAdditionalPlotLines(plotLines)); //returns an ArrayList of HIPlotLines
yaxis.setPlotLines(plotLines);
return new ArrayList<>(Collections.singletonList(yaxis));
}
If more information/parts of missing code is necessary, please ask.