charts - c3.js: possible to label x axis and multiple y axes? -
is possible define values x-axis values in c3.js chart has multiple y values?
i trying create mixed bar- , line- chart 2 y-axes , custom labels x-axis.
the result should this:
i have referred c3.js examples guide attempts: c3js.org/samples/axes_y2.html , c3js.org/samples/axes_x_tick_values.html able produce mixed line , bar chart 2 y-axes. when add in labels x-axis, however, lose second y axis:
i can chart show 2 y-axes:
<html> <head> <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.css" rel="stylesheet" type="text/css"> </head> <body> <div id="chart"></div> <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.js"></script> <script> var chart = c3.generate({ bindto: '#chart', data: { x : 'x', columns: [ ['x', 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017], ['open cases', 0, 7, 10, 12, 14, 19, 12, 17, 19, 18, 23, 24, 33, 42, 54, 63, 52, 51], ['total budget', 0, 1359300, 1700900, 2248200, 2417400, 2966846, 2966846, 2658700, 3009082, 3919996, 4212200, 4319972, 4882937, 5026751, 5671243, 5059538, 5896239, 6289674] ], axes: { 'total budget': 'y2' }, types: { 'open cases': 'bar' // add } }, axis: { y: { label: { text: 'open cases', position: 'outer-middle' } }, y2: { show: true, label: { text: 'total budget', position: 'outer-middle' } } } }); </script> </body> </html>
... once try add labels x-axis, second y axis disappears:
<html> <head> <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.css" rel="stylesheet" type="text/css"> </head> <body> <div id="chart"></div> <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.js"></script> <script> var chart = c3.generate({ bindto: '#chart', data: { x : 'x', columns: [ ['x', 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017], ['open cases', 0, 7, 10, 12, 14, 19, 12, 17, 19, 18, 23, 24, 33, 42, 54, 63, 52, 51], ['total budget', 0, 1359300, 1700900, 2248200, 2417400, 2966846, 2966846, 2658700, 3009082, 3919996, 4212200, 4319972, 4882937, 5026751, 5671243, 5059538, 5896239, 6289674] ], axes: { 'total budget': 'y2' }, types: { 'open cases': 'bar' // add } }, axis: { y: { label: { text: 'open cases', position: 'outer-middle' } }, y2: { show: true, label: { text: 'total budget', position: 'outer-middle' } } }, axis: { x: { type: 'timeseries', tick: { values: [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017] }, } } }); </script> </body> </html>
https://jsfiddle.net/qvsdvh8w/3/
am doing wrong, or limitation of c3.js? in advance sharing knowledge , insights!
just trivial syntax error you'll kick ;-)
you've declared axis
twice in configuration above
instead, put x axis declaration in axis property alongside y axes
axis: { y: { label: { text: 'open cases', position: 'outer-middle' } }, y2: { show: true, label: { text: 'total budget', position: 'outer-middle' } } }, x: { type: 'timeseries', tick: { values: [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017] }, } }
wiki
Comments
Post a Comment