Question

Is it possible to setup label names from the hash which is sent to morris?

  Morris.Bar({
    element: 'mevsother',
    data: $('#mevother').data('result'),
    xkey: 'created_at',
    ykeys: ['me', 'rank'],
    labels: ['Me', 'Them']
  });

Hash exemple:

`[{"created_at":"2014-02-24","name":"John","me":0,"rank":0}...`

So I want that one of the label to take the value of the name how can I do this? So instead of 'Them' to get the value of name: John.

Was it helpful?

Solution

You can parse your data as a variable and get the value from it. According to your hash it can be:

var result = $('#mevother').data('result');
var labels = ['Me', result[0].name];

Morris.Bar({
    element: 'mevsother',
    data: result,
    xkey: 'created_at',
    ykeys: ['me', 'rank'],
    labels: labels
  });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top