{"id":16686,"date":"2018-07-03T16:28:47","date_gmt":"2018-07-03T16:28:47","guid":{"rendered":"http:\/\/www.highcharts.com\/blog\/?p=16686"},"modified":"2026-01-12T09:57:08","modified_gmt":"2026-01-12T09:57:08","slug":"highcharts-android-wrapper-tutorial","status":"publish","type":"post","link":"https:\/\/www.highcharts.com\/blog\/integration\/highcharts-android-wrapper-tutorial\/","title":{"rendered":"Highcharts Android Wrapper Tutorial"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>In this tutorial, I will show you how to use Highcharts Android wrapper to create an interactive chart to display the UEFA champions data.<br \/>\nIf you are an Android Developer, chances are Java is your language of choice. However, you may also have some favorite tools from other platforms, such as Highcharts, the most popular enterprise charting library for the web.<\/p>\n<p>The Highcharts Android Wrapper offers you the capability to initialize the chart as a normal view in Android. This solution allows you to create a chart into a separate fragment or activity; you can also create a chart directly next to your other views without affecting them.<br \/>\nOk, let\u2019s get our hands dirty with a project to really experience the Highcharts Android Wrapper \ud83d\ude42<\/p>\n<h4>Getting started<\/h4>\n<p>Create a new Project in Android Studio, name it, choose Android 5.0 and the Empty Activity template.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-16687 aligncenter\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03111257\/Screen-Shot-2018-07-03-at-11.10.07.png\" alt=\"\" width=\"1044\" height=\"734\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03111257\/Screen-Shot-2018-07-03-at-11.10.07.png 1044w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03111257\/Screen-Shot-2018-07-03-at-11.10.07-560x394.png 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03111257\/Screen-Shot-2018-07-03-at-11.10.07-768x540.png 768w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03111257\/Screen-Shot-2018-07-03-at-11.10.07-760x534.png 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03111257\/Screen-Shot-2018-07-03-at-11.10.07-360x253.png 360w\" sizes=\"auto, (max-width: 1044px) 100vw, 1044px\" \/><\/p>\n<p>Add the Highcharts Android Framework to your project. There are two ways to do so. <b>First<\/b>, you can download the <code>aar<\/code> file and add it manually. Put the <code>aar<\/code> in the libs folder in your project structure. Then, add the following lines to the app <code>build.gradle<\/code> file:<\/p>\n<pre>repositories{\r\n\tflatDir{\r\n\t\tdirs \u2018libs\u2019\r\n\t}\r\n}<\/pre>\n<p>And following in the dependencies:<\/p>\n<pre>compile (name: 'highcharts-release-v6.1', ext:'aar')<\/pre>\n<p>The <b>second<\/b> option is to add the library to the gradle dependencies like this:<br \/>\nAdd the Highcharts repository to your build.gradle file:<\/p>\n<pre>repositories { \r\n    maven { \r\n        url \"https:\/\/highsoft.bintray.com\/Highcharts\" \r\n    }\r\n}<\/pre>\n<p>and following to the dependencies in your app <code>build.gradle<\/code> file:<\/p>\n<pre>dependencies {\r\n    compile 'com.highsoft.highcharts:highcharts:6.1r'\r\n}<\/pre>\n<p>Note, that if you plan to use the export module, you need to put this specific provider in your app:<\/p>\n<pre>&lt;provider android:authorities=\"com.your.package.name.FileProvider\"\r\n   android:name=\"android.support.v4.content.FileProvider\"\r\n   android:exported=\"false\"\r\n   android:grantUriPermissions=\"true\"&gt;\r\n   &lt;meta-data\r\n       android:name=\"android.support.FILE_PROVIDER_PATHS\"\r\n       android:resource=\"@xml\/provider_paths\"\/&gt;\r\n&lt;\/provider&gt;\r\n<\/pre>\n<p>And in add <code>provider_paths<\/code> file to <code>xml<\/code> folder containing this:<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;paths&gt;\r\n   &lt;files-path name=\"export\" path=\".\" \/&gt;\r\n&lt;\/paths&gt;\r\n<\/pre>\n<p>This completes the project setup, and you may now move on to creating your charts.<\/p>\n<h4>Creating chart to visualize team statistics using Highcharts<\/h4>\n<p>For this example, we will create a basic column chart to visualize some stats of the top 4 teams in the UEFA Champions League 2016\/17.<br \/>\nAt first, you need to create the proper <b>layout<\/b> in <code>xml<\/code> for your chart. To do this, go to your <code>activity_main.xml<\/code> and make sure the following lines are added:<\/p>\n<pre>&lt;com.highsoft.highcharts.Core.HIChartView\r\n   android:id=\"@+id\/hc\"\r\n   android:layout_width=\"match_parent\"\r\n   android:layout_height=\"match_parent\" \/&gt;\r\n<\/pre>\n<p>After creating the layout, return back to <code>MainActivity.java\/code&gt; where you create the chart. In the <\/code>onCreate method you will create first the <b>layout<\/b> from <code>xml<\/code> resource and create a new instance of the <b>HIChartView<\/b> class, passing the <b>context<\/b> from that layout:<\/p>\n<pre>HIChartView chartView = (HIChartView) findViewById(R.id.hc);<\/pre>\n<p>Done!<\/p>\n<p>Now let&#8217;s review the chart options. The <b>HIOptions<\/b> class is responsible for it. This one contains all the necessary information for data presentation and rendering the chart.<br \/>\nCreate an instance of <b>HIOptions<\/b> class:<\/p>\n<pre>HIOptions options = new HIOptions();<\/pre>\n<p>Object of this class will be used to set up all needed options for the chart. It is worth noting that only a few of them are <b>necessary<\/b> to create the chart (for example series &#8211; which will be discussed later in this article). Let\u2019s start by configuring the <b>chart<\/b> variable. To do this, we will need <b>HIChart<\/b> class:<\/p>\n<pre>HIChart chart = new HIChart();\r\nchart.setType(\u201ccolumn\u201d);\r\noptions.setChart(chart);<\/pre>\n<p>In the second line, the code above we have chosen the chart type by the type variable from the <b>HIChart<\/b> class. <b>HIChart<\/b> class offers much more, but in our example, this lone variable is sufficient. In the last line, we added chart to the options. It is a good practice to add everything to your options object at once to avoid missing some of them.<br \/>\nAt this moment it is worth giving your chart a proper title:<\/p>\n<pre>HITitle title = new HITitle();\r\n\r\ntitle.setText(\"UEFA Champions League 2016\/17\");\r\nHISubtitle subtitle = new HISubtitle();\r\nsubtitle.setText(\u201cTeam statistics\u201d);\r\noptions.setTitle(title);\r\noptions.setSubtitle(subtitle);<\/pre>\n<p>The title of the chart is managed by <b>HITitle<\/b> class, while <b>HISubtitle<\/b> is responsible for subtitle. After setting the title objects, we\u2019re adding them to the <b>options<\/b> object.<br \/>\nIt\u2019s always a good idea to change the default axes names, to make it easier for others to interpret your dataset. Set the Axis titles as follows;<\/p>\n<pre>final HIYAxis hiyAxis = new HIYAxis();\r\nhiyAxis.setMin(0);\r\nhiyAxis.setTitle(new HITitle());\r\nhiyAxis.getTitle().setText(\"Number\");\r\noptions.setYAxis(new ArrayList(){{add(hiyAxis);}});<\/pre>\n<p>We want to display the data on a category xAxis. We set the categories as an <b>ArrayList<\/b> to the <b>HIXaxis<\/b> object and assign it to the xAxis object (HIXaxis) to the options object.<\/p>\n<pre>final HIXAxis hixAxis = new HIXAxis();\r\nArrayList categories = new ArrayList&lt;&gt;();\r\ncategories.add(\"Goals\");\r\ncategories.add(\"Assists\");\r\ncategories.add(\"Shots On Goal\");\r\ncategories.add(\"Shots\");\r\n\r\nhixAxis.setCategories(categories);\r\noptions.setXAxis(new ArrayList(){{add(hixAxis);}});\r\n<\/pre>\n<p>Chart can have a few X and Y axes depending on needs, which is why it is added to options as ArrayList too.<\/p>\n<p>Now, we will configure\/set up the tooltip. Consider the following code:<\/p>\n<pre>HITooltip tooltip = new HITooltip();\r\ntooltip.setHeaderFormat(\"&lt;span style=\\\"font-size:15px\\\"&gt;{point.key}&lt;\/span&gt;&lt;table&gt;\");\r\ntooltip.setPointFormat(\"&lt;tr&gt;&lt;td style=\\\"color:{series.color};padding:0\\\"&gt;{series.name}: &lt;\/td&gt;\" + \"&lt;td style=\\\"padding:0\\\"&gt;&lt;b&gt;{point.y}&lt;\/b&gt;&lt;\/td&gt;&lt;\/tr&gt;\");\r\ntooltip.setFooterFormat(\"&lt;\/talble&gt;\");\r\ntooltip.setShared(true);\r\ntooltip.setUseHTML(true);\r\noptions.tooltip = tooltip;\r\n<\/pre>\n<p>To manage tooltip you need to create a <b>HITooltip<\/b> class. Tooltip is a small widget which is visible by hovering over the chart, displaying the values of the datapoints. You have several series and line variables available for formatting the template of the tooltip. (All formatters variables are explained in the <a href=\"https:\/\/api.highcharts.com\/android\/highcharts\/\" target=\"_blank\" rel=\"noopener noreferrer\">documentation<\/a>).<br \/>\nIn this article, it is worth noting that you must turn on the <b>useHTML<\/b> flag to let your tooltip use HTML formatting. Whereas the <b>share<\/b> flag lets you show one tooltip, but showing shared values whether the series you tap are from the same category or not.<\/p>\n<p>At this moment, let\u2019s add some chart type specific options:<\/p>\n<pre>HIPlotOptions plotOptions = new HIPlotOptions();\r\nplotOptions.setColumn(new HIColumn());\r\nplotOptions.getColumn().setPointPadding(0.2);\r\nplotOptions.getColumn().setBorderWidth(0);\r\noptions.setPlotOptions(plotOptions);<\/pre>\n<p>In the above code, we added new <b>HIPlotOptions<\/b> class object. This object is designed to assign specific options to all series in the chart for a specific series type. In this case, the setter <code>setColumn()<\/code> is needed here because the plot options are applying to our column series. The <b>pointPadding<\/b> is adding padding space between each column and <b>borderWidth<\/b> sets the width of the border surrounding each column.<\/p>\n<p>For now, we were talking only about options in our column chart. You may ask: where do we set the data in here exactly? Well, we will add them now!<\/p>\n<pre>HIColumn realMadrid = new HIColumn();\r\nrealMadrid.setName(\"Real Madrid\");\r\nArrayList realMadridData = new ArrayList&lt;&gt;();\r\nrealMadridData.add(36);\r\nrealMadridData.add(31);\r\nrealMadridData.add(93);\r\nrealMadridData.add(236);\r\nrealMadrid.setData(realMadridData);\r\n\r\nHIColumn juventus = new HIColumn();\r\njuventus.setName(\"Juventus\");\r\nArrayList juventusData = new ArrayList&lt;&gt;();\r\njuventusData.add(22);\r\njuventusData.add(10);\r\njuventusData.add(66);\r\njuventusData.add(178);\r\njuventus.setData(juventusData);\r\n\r\nHIColumn monaco = new HIColumn();\r\nmonaco.setName(\"Monaco\");\r\nArrayList monacoData = new ArrayList&lt;&gt;();\r\nmonacoData.add(22);\r\nmonacoData.add(17);\r\nmonacoData.add(56);\r\nmonacoData.add(147);\r\nmonaco.setData(monacoData);\r\n\r\nHIColumn atleticoMadrid = new HIColumn();\r\natleticoMadrid.setName(\"Atl\u00e9tico Madrid\");\r\nArrayList atleticoMadridData = new ArrayList&lt;&gt;();\r\natleticoMadridData.add(15);\r\natleticoMadridData.add(9);\r\natleticoMadridData.add(55);\r\natleticoMadridData.add(160);\r\natleticoMadrid.setData(atleticoMadridData);\r\n<\/pre>\n<p>In the above long code snippet, you can see we instantiated four separate columns. Each of them contains data for the football clubs. Let\u2019s talk about first one (the rest is done in the same way). At first, we created the <b>HIColumn<\/b> object which is responsible for column implementation. Next, we added the name for it and created another ArrayList holding the datapoints. At this moment, you are probably curious why we didn\u2019t add any of those columns to options object yet. That\u2019s because Columns are held by <b>HISeries<\/b> object. We need to add them to the <b>series<\/b> first! See here below;<\/p>\n<pre>ArrayList series = new ArrayList&lt;&gt;();\r\nseries.add(realMadrid);\r\nseries.add(juventus);\r\nseries.add(monaco);\r\nseries.add(atleticoMadrid);\r\n\r\noptions.setSeries(series);\r\n<\/pre>\n<p><b>Series<\/b> is a special ArrayList containing <b>HISeries<\/b> objects. Each of chart type objects extends <b>HISeries<\/b> class, so we can add all our columns to the list without any trouble. In the last one, we add all columns as one ArrayList object to the options.<\/p>\n<p>Now, when all settings are made, we can finish our work by assigning the configuration options to the <b>chartView<\/b> created at the beginning:<\/p>\n<pre>chartView.setOptions(options);<\/pre>\n<p>The result should look like this, congratulations!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-16706 aligncenter\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03150058\/Screen-Shot-2018-07-03-at-11.11.51.png\" alt=\"\" width=\"645\" height=\"945\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03150058\/Screen-Shot-2018-07-03-at-11.11.51.png 645w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03150058\/Screen-Shot-2018-07-03-at-11.11.51-300x440.png 300w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03150058\/Screen-Shot-2018-07-03-at-11.11.51-403x590.png 403w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03150058\/Screen-Shot-2018-07-03-at-11.11.51-191x280.png 191w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/07\/03150058\/Screen-Shot-2018-07-03-at-11.11.51-614x900.png 614w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A step by step tutorial to learn how to use the official Highcharts Android Wrapper to set up interactive chart.<\/p>\n","protected":false},"author":231,"featured_media":21423,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"meta_title":"","meta_description":"","hc_selected_options":[],"footnotes":""},"categories":[1105],"tags":[1094,1031],"coauthors":[757],"class_list":["post-16686","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-integration","tag-highcharts-core","tag-javascript"],"_links":{"self":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/16686","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/users\/231"}],"replies":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/comments?post=16686"}],"version-history":[{"count":1,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/16686\/revisions"}],"predecessor-version":[{"id":29140,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/16686\/revisions\/29140"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media\/21423"}],"wp:attachment":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media?parent=16686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/categories?post=16686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/tags?post=16686"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/coauthors?post=16686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}