AnyChart / AnyChart-Android

AnyChart Android Chart is an amazing data visualization library for easily creating interactive charts in Android apps. It runs on API 19+ (Android 4.4) and features dozens of built-in chart types.
2.31k stars 369 forks source link

Choropleth Map listener issue #115

Open margin555 opened 5 years ago

margin555 commented 5 years ago

In Choropleth Map how can I detect the clicked state (states in the US) and also how can I enable multiple states click

Shestac92 commented 5 years ago

@margin555 Unfortunately, the current version of the library doesn't provide a listener on multiple selections, only on a single click/select. The snippet below describes how to achieve that (the map file is placed in app assets, getData() returns the series data:

        Map map = AnyChart.map();

        map.geoData("anychart.maps.united_states_of_america");

        Choropleth series = map.choropleth(getData());

        map.setOnClickListener(new ListenersInterface.OnClickListener(new String[]{"id", "name", "value"}) {
            @Override
            public void onClick(Event event) {
                event.getData().get("id");
                event.getData().get("name");
                event.getData().get("value");

                Log.d("MapListener", event.getData().get("id"));
            }
        });

        anyChartView.addScript("file:///android_asset/united_states_of_america.js");
        anyChartView.addScript("file:///android_asset/proj4.js");
        anyChartView.setChart(map);