I am trying to display sales trend using frappe chart on a new page. I have followed some discussion already posted on frappe chart and able to display a graph on a new page based on static data.
Can someone please share sample code how can I connect to database and fetch details in my new page. My current .js file for frappe chart is as follows…
frappe.pages[‘dashboard1’].on_page_load = function(wrapper) {
var page = frappe.ui.make_app_page({
parent: wrapper,
title: ‘DashBoard’,
single_column: true
});
frappe.breadcrumbs.add("Accounts")
page.add_menu_item('Sales Invoice' , ()=> frappe.set_route('List', 'Sales Invoice'))
page.add_menu_item('Purchase Invoice', ()=> frappe.set_route('List', 'Purchase Invoice'))
const container = '.layout-main-section';
jqcontainer = $(container);
const dedicated_div = '.dedicated-chart-div';
let chart_div = $("<div class=\"dedicated-chart-div\"></div>");
chart_div.appendTo(jqcontainer);
const options = {
parent: $(page.dedicated_div),
data: {
labels: ["Jan", "Feb","Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
datasets: [
{
name: "Some Data", type: "bar",
values: [25, 40, 30, 35, 8, 52, 17, -4, 30, 35, 8, 52]
},
]
},
title: "My Awesome Chart on a page in ERPNext",
type: 'bar',//'axis-mixed',
height: 250,
colors: ['#7cd6fd']
}
const chart = new frappeChart.Chart(dedicated_div, options)
setTimeout(function () {chart.draw(!0)}, 1);
}