Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String value in y axis morris javascript

Tags:

morris.js

What's wrong with this morrisjs javascript ? http://jsbin.com/dituriheje/edit?html,js,output )

<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
  <script src="http://cdn.oesmith.co.uk/morris-0.4.1.min.js"></script>
<meta charset=utf-8 />
<title>Morris.js Line Chart Example</title>
</head>
<body>
  <div id="js_stats"></div>
  <script>
    Morris.Line({
  element: 'js_stats',
  data: [
    {y: "Context 1", E: 0.0247578, D: 0.0250694, A: 0.00205555, B: 0.00445085, C: 0.011262},
    {y: "Context 2", E: 0.025153150000000003, D: 0.02422775, A: 0.0020365, B: 0.0044665, C: 0.01137645},
    {y: "Context 3", E: 0.0254322, D: 0.024671699999999998, A: 0.0022679, B: 0.0045135, C: 0.0114602},
    {y: "Context 4", E: 0.02603472, D: 0.0249791, A: 0.00192968, B: 0.00437542, C: 0.01089924},
    {y: "Context 5", E: 0.025053799999999998, D: 0.0255343, A: 0.002256, B: 0.0043565, C: 0.0118452}
  ],
  xkey: 'y',
  ykeys: ["A", "B", "C", "D", "E"],
  labels: ["Strategy 1", "Strategy 2", "Strategy 3", "Strategy 4", "Strategy 5"]
});
  </script>
</body>
</html>

Morris work if i set int value in y axis, like y: "1". But i want String value, how to do that ?

like image 557
bux Avatar asked Feb 24 '26 18:02

bux


1 Answers

Morris graphs will normally try to interpret strings as dates (Docs). To prevent this use parseTime : false as an option to the Morris.line.

It is then up to you to ensure that there is sufficient room for the labels. You can play with xLabelAngle to make it fit.

like image 59
James K Avatar answered Feb 27 '26 21:02

James K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!