Flotador Con eje x" Cadena"
Al usar flot me gustaría tener un eje x basado en cadenas. Por ejemplo, tengo una lista de clientes "Bob", "Chris", " Joe " y me gustaría trazar sus ingresos en el eje Y. (este es un gráfico de barras)
Parece a primera vista que flot solo admite tipos numéricos en el eje x. ¿Es esto cierto?
3 answers
@Matt está cerca, pero tendría más sentido usar la opción ticks
para especificar directamente qué marcas deben tener qué etiquetas:
var options = {
...
xaxis: {
ticks: [[0,'Bob'],[1,'Chris'],[2,'Joe']]
}
...
};
EDITAR : se parece a este (Agregué más datos que etiquetas, pero entiendes la idea).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:18:20
El plugin de categorías (jquery.flot.categorías.js) hará esto bastante bien, para que los datos puedan formatearse de la siguiente manera:
var data = [ ["January", 10], ["February", 8], ["March", 4], ["April", 13], ["May", 17], ["June", 9] ];
Y trazar así:
Véase: http://www.flotcharts.org/flot/examples/categories/index.html
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-19 16:27:55
Debería poder hacer esto usando la opción tickFormatter
según esta pregunta. No lo he probado yo mismo, pero dale una oportunidad:
var xAxisLabels = ['Bob', 'Chris', 'Joe'];
function xAxisLabelGenerator(x){
return xAxisLabels[x];
}
var plot = $.plot($("#placeholder"), {
// snip other options...
xaxis: {
transform: xAxisLabelGenerator,
tickFormatter: xAxisLabelGenerator
}
});
Esto significa que los valores reales de x deben ser 0, 1, 2, ...
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:18:20