A few days ago I saw HighCharts Library is available for Android for graph.
https://github.com/highcharts/highcharts-android
I read the documentation and start it to add on my project but when I am trying to add gradle to my project I'm getting error:
Error:Failed to resolve: com.highsoft.highcharts:6.0.2:
Open File
There are two ways as they mentioned in their documentation:
A) You can download the aar from here: Highcharts and add it manually. Put the aar in the libs folder in your project structure.
B) You can add the library to the gradle dependecies from JCenter.
When I added .aar file to libs folder there is no issue but when I added below code:
HIGChartView chartView = (HIGChartView) findViewById(R.id.hc);
My project not able to find out class HIGChartView
. I'm not able to find out whether it's my side issue or HighCharts Library issue.
I also downloaded poject by Github, Getting no issue on their Project also compare Gradle with their project but I'm not able to find out the issue.
My build.gradle(Module:App) :
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.kabloom.highcharts2"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.highsoft.highcharts:6.0.2' // HighCharts here added
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
After creating issue on github they replied and solved my issue...
Their Documentation having problem :
Incorrect Class :
HIGChartView chartView = (HIGChartView) findViewById(R.id.hc);
Correct Class :
HIChartView chartView = (HIChartView) findViewById(R.id.hc);
And Please note that the library need Gson to work so add it in your dependencies like this:
compile 'com.google.code.gson:gson:2.8.0'
Also , They replied :
Unfortunatelly Highcharts Android is not avilable from jcenter yet so you need to add library manually. You can do that by following direct instructions from A) point from readme.
Reference Working Code :
build.gradle(Module:App):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.package_name.highchartdemo"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories{
flatDir{
dirs 'libs'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
compile (name: 'highcharts-release', ext:'aar')
compile 'com.google.code.gson:gson:2.8.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
MainActivity :
package com.package_name.highchartdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.highsoft.highcharts.Core.*;
import com.highsoft.highcharts.Common.HIChartsClasses.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
HIChartView chartView = (HIChartView) findViewById(R.id.hc);
HIOptions options = new HIOptions();
HIChart chart = new HIChart();
chart.type = "column";
options.chart = chart;
HITitle title = new HITitle();
title.text = "Demo chart";
options.title = title;
HIColumn series = new HIColumn();
series.data = new ArrayList<>(Arrays.asList(49.9, 71.5, 106.4, 129.2, 144, 176, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4));
options.series = new ArrayList<HISeries>(Collections.singletonList(series));
chartView.options = options;
}
}
activity_main:
<?xml version="1.0" encoding="utf-8"?>
<com.highsoft.highcharts.Core.HIChartView 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:orientation="vertical"
android:id="@+id/hc"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.package_name.highchartdemo.MainActivity"/>