Hello, I am trying to create a chart snippet using data from the controller and using that data to create a Chart snippet.
Here is what I have managed to do and I am getting this error from the console.
Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)
Controller:
@http.route ( '/btc/usd' , auth = "public" , type = "json" , methods =[ 'POST' , 'GET' ] , csrf = False )
def all_bitcoin_usd ( self , **kwargs ):
print ( 'Calling this method >>>' )
# fetch_usd = http.request.env['usd.btc.exchange'].search_read([], ['name', 'date', 'amount_paid'])
fetch_usd = http.request.env[ 'usd.btc.exchange' ].search([])
for i infetch_usd:
print ( 'fetch usd' , i)
param = {}
data = dict ()
data[ 'name' ] = i.name
data[ 'date' ] = i.date
data[ 'amount_paid' ] = i.amount_paid
param[ 'param' ] = data
n = json.dumps(param)
print ( 'nnn' , n)
return Response(json.dumps(param , default =date_utils.default) , content_type = 'application/json;charset=utf -8' ,status = 200 )
js file
odoo.define( 'dynamic_jobs_snippets.s_bitcoin_chart_temp2' , function (require) {
var PublicWidget = require( 'web.public.widget' );
var rpc = require( 'web.rpc' );
var Dynamic = PublicWidget.Widget.extend( {
selector: '.usd_bitcoin_chart_can2' ,
start: function () {
var self = this ;
rpc.query({
route: '/btc/usd' ,
params: {},
}).then((result) => {
console .log(result);
const myChart = new Chart({
type: 'line' ,
data: {
labels: result.param[ 'name' ],
datasets: [{
label: 'My First Dataset' ,
data: result.param[ 'amount_paid' ],
fill: true ,
backgroundColor: 'rgba(255, 99, 132, 0.2)' ,
borderColor: 'rgb(255, 99, 132)' ,
pointBackgroundColor: 'rgb(255, 99, 132)' ,
pointBorderColor: '#fff' ,
pointHoverBorderColor: 'rgb(255, 99, 132)'
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
});
},
});
PublicWidget.registry.usd_bitcoin_chart_can2 = Dynamic;
return Dynamic;
});
Canvas UI
="usd_bitcoin_chart " height="400px" width="400px"/>