hi guys,
can anyone check if this code correct or not my purpose is to show multiple chart lines but from the same table in database :
js file :
frappe.query_reports[“flow rate”] = {
“filters”: [
{
“fieldname”:“from_date”,
“label”: __(“From Date”),
“fieldtype”: “Date”,
‘reqd’: 1,
“default”: frappe.datetime.add_days(frappe.datetime.nowdate(), -15)
},
{
“fieldname”:“to_date”,
“label”: __(“To Date”),
“fieldtype”: “Date”,
‘reqd’: 1,
“default”:frappe.datetime.nowdate()
},
],
get_chart_data: function(columns, result) {
return {
data: {
x: ‘Date’,
columns: [
[‘Date’].concat($.map(result, function(d) { return d[0][0]; })),
[‘KSR0’].concat($.map(result, function(d) { return d[1][0]; })),
[‘KSR1’].concat($.map(result, function(d) { return d[2][0]; })),
[‘KSR2’].concat($.map(result, function(d) { return d[3][0]; }))
]}, axis: { x: { type: 'timeseries', tick: { format: frappe.ui.py_date_format } } }, chart_type: 'line',
}
}
}
py file :
from future import unicode_literals
import frappe
def execute(filters=None):
columns = [
{
‘fieldname’: ‘creation_date’,
‘label’: ‘Date’,
‘fieldtype’: ‘Date’
},
{
‘fieldname’: ‘KSR0’,
‘fieldtype’: ‘Float’,
‘label’: ‘KSR0’
},
{
‘fieldname’: ‘KSR1’,
‘fieldtype’: ‘Float’,
‘label’: ‘KSR1’
},
{
‘fieldname’: ‘KSR2’,
‘fieldtype’: ‘Float’,
‘label’: ‘KSR2’
},
]
data[0] = frappe.db.sql(‘’‘select date(creation) as creation_date,
flow_rate as ksr0
from tabProduction
where date(creation) between %s and %s
and well = ‘KSR0’
group by creation_date order by creation_date desc’‘’, (filters.from_date, filters.to_date))
data[1] = frappe.db.sql(‘’‘select date(creation) as creation_date,
flow_rate as ksr1
from tabProduction
where date(creation) between %s and %s
and well = ‘KSR1’
group by creation_date order by creation_date desc’‘’, (filters.from_date, filters.to_date))
data[2] = frappe.db.sql(‘’‘select date(creation) as creation_date,
flow_rate as ksr2
from tabProduction
where date(creation) between %s and %s
and well = ‘KSR2’
group by creation_date order by creation_date desc’‘’, (filters.from_date, filters.to_date))
return columns, data
many thanks.