I have this morris chart that I would like to refresh using a javascript function. So I then can add a href link on the page that contains that javascript that will refresh the morris chart.
<script type="text/javascript">
$.get('@Url.Action("GetData")', function (result) {
Morris.Line({
element: 'samplechart',
data: result,
xkey: 'period',
ykeys: ['a', 'b'],
labels: ['YES', 'NO'],
xLabelAngle: 60,
parseTime: false,
resize: true,
lineColors: ['#32c5d2', '#c03e26']
});
});
</script>
How would that javascrip funcion look and how do I call it?
You can create a function that initialize your Morris Line Chart without the data:
initMorris
. Then to set the data in your chart, on page load or on link clicked, call the functiongetMorris
that gets the data and set the data to the chartsetMorris
using the built-insetData
function of the Morris Line.Please try the snippet below (for the example, I created a
getMorrisOffline
function. To get data with ajax, usegetMorris
instead in page load and in the link event onclick):