Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to plot pie chart with changing data on user click? #85

Closed
Jeetin9410 opened this issue Mar 12, 2019 · 7 comments
Closed

How to plot pie chart with changing data on user click? #85

Jeetin9410 opened this issue Mar 12, 2019 · 7 comments
Assignees

Comments

@Jeetin9410
Copy link

I m using the trial version , and trying to plot pie chart.....In my case the data for pie chart changes on user click.
Please tell me how to implement this thing. What is happening now is that the first data that i used to set in pie, is getting permanent.....and whatever the data i set for next time does not work with pie chart. The piechart shows the same data of very first time.Please help `

private void generateGraph(int unmarked,int absent,int present,int latePresent){
// these are absent, present of student
Log.e( "unG",unmarked+"" );
Log.e( "abG",absent+"" );
Log.e( "PrG",present+"" );
Log.e( "LpG",latePresent+"" );
final Pie pie = AnyChart.pie();

    pie.setOnClickListener(new ListenersInterface.OnClickListener(new String[]{"x", "value"}) {
        @Override
        public void onClick(Event event) {
            Toast.makeText(getContext(), event.getData().get("x") + ":" + event.getData().get("value"), Toast.LENGTH_SHORT).show();
        }
    });

    List<DataEntry> data1 = new ArrayList<>();
    data1.add(new ValueDataEntry("Unmarked", unmarked));
    data1.add(new ValueDataEntry("Absent", absent));
    data1.add(new ValueDataEntry("Present", present));
    data1.add(new ValueDataEntry("LatePresent", latePresent));

    pie.data(data1);

    pie.title("Attendance Chart ");
    pie.legend()
            .position("center")
            .itemsLayout( LegendLayout.HORIZONTAL)
            .align( Align.CENTER);
    anyChartView.setChart(pie);
}`
@Shestac92
Copy link

@Jeetin9410
Check this code sample which describes how to update the pie chart. You can use the same approach to update your chart on the click event.

@Shestac92 Shestac92 self-assigned this Mar 13, 2019
@Jeetin9410
Copy link
Author

The sample code you listed will work for updating the pie chart after some time delay....But I want it to change on user click.....Whatever the data user selects....The pie chart respectively to that data should be displayed.

@Shestac92
Copy link

@Jeetin9410
You can execute the chart updating in any event handler.
You can use the chart listeners, for details, please check this wiki article.

@Jeetin9410
Copy link
Author

Jeetin9410 commented Mar 13, 2019

I tried the Custom data Entry code , you mentioned but i was unable to set data in piechart due this syntax
pie.setData(data);
Android studio is showing the error as " Cannot resolve method 'setData()' "
Please suggest something!!

@Shestac92
Copy link

@Jeetin9410
I'm afraid the wiki article provides deprecated API.
Use pie.data(data); instead of pie.setData() just like in this sample.

@Jeetin9410
Copy link
Author

From the beginning , i was using the same i.e "pie.data(data)" and nothing is working accordingly.

@Shestac92
Copy link

@Jeetin9410
I have just checked the code using the current version of the library and it works well.
pieUpdate

I used the code provided in the previous comment.

What version of the library are you using? Please, try to update your library up to the latest version. This approach will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants