I am trying to add an AnyChart HeatMap Chart to my ANdroid Studio Java app. To learn about implementing it I am starting by using the AnyChart HeatMap exmaple code. Upon running my app and opening the activity window that displays the chart it shows the following error in the run tab at the bottom of Android Studio. Also, the app when the activity window opens for the HeatMap Chart is comes up and a white blank window.
I get this in my error in the "run" tab in Android studio:
D/EGL_emulation: app_time_stats: avg=867.14ms min=16.75ms max=6646.87ms count=8 I/WebViewFactory: Loading com.google.android.webview version 95.0.4638.74 (code 463807437) W/.example.hortu: Accessing hidden method Landroid/os/Trace;->isTagEnabled(J)Z (unsupported, reflection, allowed) W/.example.hortu: Accessing hidden method Landroid/os/Trace;->traceBegin(JLjava/lang/String;)V (unsupported, reflection, allowed) W/.example.hortu: Accessing hidden method Landroid/os/Trace;->traceEnd(J)V (unsupported, reflection, allowed) W/.example.hortu: Accessing hidden method Landroid/os/Trace;->asyncTraceBegin(JLjava/lang/String;I)V (unsupported, reflection, allowed) W/.example.hortu: Accessing hidden method Landroid/os/Trace;->asyncTraceEnd(JLjava/lang/String;I)V (unsupported, reflection, allowed) I/cr_WVCFactoryProvider: Loaded version=95.0.4638.74 minSdkVersion=29 isBundle=false multiprocess=true packageId=2 I/cr_VariationsUtils: Failed reading seed file "/data/user/0/com.example.hortus/app_webview/variations_seed_new" I/cr_VariationsUtils: Failed reading seed file "/data/user/0/com.example.hortus/app_webview/variations_seed" I/cr_LibraryLoader: Successfully loaded native library I/cr_CachingUmaRecorder: Flushed 8 samples from 8 histograms. W/chromium: [WARNING:dns_config_service_android.cc(153)] Failed to read DnsConfig. E/chromium: [ERROR:network_service_instance_impl.cc(179)] Failed to grant sandbox access to network context data for /data/user/0/com.example.hortus/app_webview/Default with result 7: No such file or directory (2) D/CompatibilityChangeReporter: Compat change id reported: 171228096; UID 10148; state: ENABLED W/.example.hortu: Accessing hidden method Landroid/media/AudioManager;->getOutputLatency(I)I (unsupported, reflection, allowed) D/HostConnection: createUnique: call D/HostConnection: HostConnection::get() New Host Connection established 0x7c704dc1e590, tid 16265 W/cr_media: Requires BLUETOOTH permission D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri ANDROID_EMU_read_color_buffer_dma ANDROID_EMU_hwc_multi_configs GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 E/chromium: [ERROR:gl_surface_egl.cc(584)] eglChooseConfig failed with error EGL_SUCCESS D/EGL_emulation: eglCreateContext: 0x7c704dc1d8d0: maj 2 min 0 rcv 2 D/EGL_emulation: eglMakeCurrent: 0x7c704dc1d8d0: ver 2 0 (tinfo 0x7c7272a2a100) (first time) E/chromium: [ERROR:gl_surface_egl.cc(584)] eglChooseConfig failed with error EGL_SUCCESS D/EGL_emulation: eglCreateContext: 0x7c704dc20c90: maj 2 min 0 rcv 2 D/EGL_emulation: app_time_stats: avg=8.06ms min=3.42ms max=31.32ms count=33 I/Choreographer: Skipped 53 frames! The application may be doing too much work on its main thread. D/EGL_emulation: eglCreateContext: 0x7c704dc1d8d0: maj 2 min 0 rcv 2 I/OpenGLRenderer: Davey! duration=1000ms; Flags=1, FrameTimelineVsyncId=19783, IntendedVsync=5347614875222, Vsync=5348498208520, InputEventId=0, HandleInputStart=5348507529000, AnimationStart=5348507578000, PerformTraversalsStart=5348510589100, DrawStart=5348585297400, FrameDeadline=5347631541888, FrameInterval=5348506764600, FrameStartTime=16666666, SyncQueued=5348588150600, SyncStart=5348609703100, IssueDrawCommandsStart=5348610035600, SwapBuffers=5348619661900, FrameCompleted=5348636693000, DequeueBufferDuration=36800, QueueBufferDuration=15211600, GpuCompleted=5348636405500, SwapBuffersCompleted=5348636693000, DisplayPresentTime=0, D/EGL_emulation: app_time_stats: avg=249.81ms min=34.80ms max=1027.62ms count=6
my java code is:
package com.example.hortus;
import android.os.Bundle;
import android.webkit.WebView;
import androidx.appcompat.app.AppCompatActivity;
import com.anychart.AnyChart;
import com.anychart.AnyChartView;
import com.anychart.chart.common.dataentry.DataEntry;
import com.anychart.chart.common.dataentry.HeatDataEntry;
import com.anychart.charts.HeatMap;
import com.anychart.enums.SelectionMode;
import com.anychart.graphics.vector.SolidFill;
import java.util.ArrayList;
import java.util.List;
public class VPDChartActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vpd_chart);
AnyChartView anyChartView = findViewById(R.id.any_chart_view);
anyChartView.webview.getSettings().setDomStorageEnabled(true);
anyChartView.setProgressBar(findViewById(R.id.progress_bar));
HeatMap riskMap = AnyChart.heatMap();
riskMap.stroke("1 #fff");
riskMap.hovered()
.stroke("6 #fff")
.fill(new SolidFill("#545f69", 1d))
.labels("{ fontColor: '#fff' }");
riskMap.interactivity().selectionMode(SelectionMode.NONE);
riskMap.title().enabled(true);
riskMap.title()
.text("Risk Matrix in Project Server")
.padding(0d, 0d, 20d, 0d);
riskMap.labels().enabled(true);
riskMap.labels()
.minFontSize(14d)
.format("function() {\n" +
" var namesList = [\"Low\", \"Medium\", \"High\", \"Extreme\"];\n" +
" return namesList[this.heat];\n" +
" }");
riskMap.yAxis(0).stroke(null);
riskMap.yAxis(0).labels().padding(0d, 15d, 0d, 0d);
riskMap.yAxis(0).ticks(false);
riskMap.xAxis(0).stroke(null);
riskMap.xAxis(0).ticks(false);
riskMap.tooltip().title().useHtml(true);
riskMap.tooltip()
.useHtml(true)
.titleFormat("function() {\n" +
" var namesList = [\"Low\", \"Medium\", \"High\", \"Extreme\"];\n" +
" return '<b>' + namesList[this.heat] + '</b> Residual Risk';\n" +
" }")
.format("function () {\n" +
" return '<span style=\"color: #CECECE\">Likelihood: </span>' + this.x + '<br/>' +\n" +
" '<span style=\"color: #CECECE\">Consequence: </span>' + this.y;\n" +
" }");
List<DataEntry> data = new ArrayList<>();
data.add(new CustomHeatDataEntry("Rare", "Insignificant", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Rare", "Minor", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Rare", "Moderate", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Rare", "Major", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Rare", "Extreme", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Unlikely", "Insignificant", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Unlikely", "Minor", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Unlikely", "Moderate", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Unlikely", "Major", 1, "#ffb74d"));
data.add(new CustomHeatDataEntry("Unlikely", "Extreme", 1, "#ffb74d"));
data.add(new CustomHeatDataEntry("Possible", "Insignificant", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Possible", "Minor", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Possible", "Moderate", 1, "#ffb74d"));
data.add(new CustomHeatDataEntry("Possible", "Major", 1, "#ffb74d"));
data.add(new CustomHeatDataEntry("Possible", "Extreme", 1, "#ffb74d"));
data.add(new CustomHeatDataEntry("Likely", "Insignificant", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Likely", "Minor", 1, "#ffb74d"));
data.add(new CustomHeatDataEntry("Likely", "Moderate", 1, "#ffb74d"));
data.add(new CustomHeatDataEntry("Likely", "Major", 2, "#ef6c00"));
data.add(new CustomHeatDataEntry("Likely", "Extreme", 2, "#ef6c00"));
data.add(new CustomHeatDataEntry("Almost\\nCertain", "Insignificant", 0, "#90caf9"));
data.add(new CustomHeatDataEntry("Almost\\nCertain", "Minor", 1, "#ffb74d"));
data.add(new CustomHeatDataEntry("Almost\\nCertain", "Moderate", 1, "#ffb74d"));
data.add(new CustomHeatDataEntry("Almost\\nCertain", "Major", 2, "#ef6c00"));
data.add(new CustomHeatDataEntry("Almost\\nCertain", "Extreme", 3, "#d84315"));
riskMap.data(data);
anyChartView.setChart(riskMap);
}
private static class CustomHeatDataEntry extends HeatDataEntry {
CustomHeatDataEntry(String x, String y, Integer heat, String fill) {
super(x, y, heat);
setValue("fill", fill);
}
}
}
my xml code is:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".VPDChartActivity">
<!-- Page Title -->
<TextView
android:id="@+id/text_view_vpd_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title_activity_vpd_hm_chart"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="@+id/progress_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/progress_bar" />
<com.anychart.AnyChartView
android:id="@+id/any_chart_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/any_chart_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have searched the internet to no avail....
I have found that setting:
anyChartView.webview.getSettings().setDomStorageEnabled(true);
should fix the issue but when I try to use it the import of "import android.webkit.WebView;" stays grey and shows it isn't used.
as well as the "webview" of anyChartView.webview.getSettings().setDomStorageEnabled(true);
show red and states "cannot resolve symbol.
I understand what "cannot resolve symbol means and thought the import would solve that.
I am just stuck and after three weeks on this I am finally coming here for help.
To correct this issue:
My code was correct, however at the end it wasn't drawing the view.
added after:
riskMap.data(data);
anyChartView.setChart(riskMap);
This line to resolve the issue.
riskMap.draw(true);
In other Anychart charts using Cartesian, such as bar, line, and combination graphs of bars and lines, etc....use:
after this:
anyChartView.setChart(cartesian);
Add this line to draw the view:
cartesian.draw(true);
either way at the end a ".draw()" must be included.