Quiero pasar una variable de instancia @datos
que viene del controlador; de la vista a un javascript embebido y no logro hacer que el javascript lo reconozca, anexo código:
Controlador: inicio_controller.rb
def data
@datos = [{ name: 'Pedacito', data: [["Muestra A", 5],["Muestra B", 17],["Muestra C", 23],["Muestra D", 7]] }]
end
Vista: data.slim
script src="https://code.highcharts.com/highcharts.js"
hr
#PieCustom1
hr
javascript:
Highcharts.chart('PieCustom1', {
chart: {type: 'pie',},
title: {text: 'Titulo de pie Donut in Highcharts'},
subtitle: {text: 'Subtitulo de pie Donut in Highcharts'},
tooltip: {
backgroundColor: '#FCFFC5',
borderColor: 'black',
borderRadius: 10,
borderWidth: 3,
formatter: function() {
return '<b>' + this.point.name + '</b><br>' + Highcharts.numberFormat(this.percentage, 1) + '%';
},
},
plotOptions: {
pie: {
innerSize: 100,
depth: 45,
dataLabels: {
enabled: true,
format: '<b>{point.name}</b><br>{y} pedacitos',
distance: -45
}
}
},
series: '<%= "#{@datos}" %>',
});
#{@datos}
debería funcionar