mattosaurus / ChartJSCore

Implementation of Chart.js for use with .NET Core.
GNU General Public License v3.0
116 stars 34 forks source link

How to change chart type from front end #82

Closed fasteddys closed 2 years ago

fasteddys commented 2 years ago

Hello this is great, I see many widget that allow the user to switch between a bar graph to a column etc from the front end in a dashboard.

Can you please share some guidance or a sample from and ASP MVC Core 6 view

mattosaurus commented 2 years ago

Hi, you can update the data in a chart and refresh the chart but you can't change the type of chart.

You're best bet is probably to render multiple canvases and hide the ones you're not using and to use a dropdown to unhide the selected canvas.

fasteddys commented 2 years ago

Hello @mattosaurus thanks for the response, here is sample code to post back the change in chart type

https://jsfiddle.net/canvasjs/yzewncsh/ - can we incorporate this or this https://stackoverflow.com/q/25443627/6085193

mattosaurus commented 2 years ago

You should be able to do the one linked in the jsfiddle. ChartJSCore just outputs javascript to your HTML view so you could add in more javascript there to hook into it and rerender when a dropdown is changed.

fasteddys commented 2 years ago

thanks, since some of this is configured/ set rendered in the backend, what action would I trigger, or post to so that it can rewrap and get that served back to the client.

Or would I not need to go back to the server?