Why am I not able to pass a variable to my JavaScript code?
Have you try changing the order?

First load the drupalSettings attachment and after the library?

$build['#attached']['drupalSettings']['module_machine_name']['morris']['memGraph'] = $graph_total;
$build['#attached']['library'][] = 'module_machine_name/morris';