Google Charts - Hide line when clicking legend key

后端 未结 3 1386
挽巷
挽巷 2021-01-19 00:24

I\'d like to be able to show/hide the lines on my line graph when clicking the relevant key in the legend, is this possible?

3条回答
  •  天涯浪人
    2021-01-19 00:36

    To hide show lines on your GWT Visualization LineChart, follow these steps:-

    1.Create a DataView object based on an existing DataTable object:

    DataTable dataTable = DataTable.create();
    DataView dataView = DataView.create(dataTable);
    

    2.Hide the column of the curve/line that you want to hide in the DataView:

    dataView.hideColumns(new int[]{});
    

    3.Draw the entire chart again based on the DataView:

    chart.draw(dataView, getOptions());
    

    Please note that there is a caveat here, step 3 is a costly step, for us it is taking almost 20-30 sec. for the the new graph to be drawn. But if the data is not large it should be manageable in your context.

    Note: You will have to make your own legend with a checkbox and do the above stuff when user checks/unchecks a checkbox.

提交回复
热议问题