Try ERPNext Buy Support Partners Foundation Foundation Members

Multiple Dashboard Line Charts as a Single Chart

Is it possible to overlap two or more dashboards line charts in a single chart.
Use case: I want to track payments received and payment paid on the same chart.

I came to know that ERPNext uses Frappe Charts
For any one trying to achieve the multiple graphed charts in ERPNext must make custom chart source and return multiple datasets in .py file:

.py file for mapping accounts receivable and payable on the same chart. How ever I could not find a way to define chart colors and other attributes mentioned at Frappe Charts as they are generated in .js. Only one color can be changed while defining dashboard chart. Frappe Charts are very nice and anyone wants to leverage them can directly use ERPNext Page to write .js and .py files of the Page for adding charts to page and play with all the attributes.

Copyright © 2015, Frappe Technologies Pvt. Ltd. and Contributors

License: GNU General Public License v3. See license.txt

from future import unicode_literals
import frappe, json
from frappe.utils import add_to_date, date_diff, getdate, nowdate, get_last_day, formatdate
from import execute
from import cache_source, get_from_date_from_timespan
from frappe.desk.doctype.dashboard_chart.dashboard_chart import get_period_ending

from frappe.utils.nestedset import get_descendants_of

def get(chart_name = None, chart = None, no_cache = None, from_date = None, to_date = None):
if chart_name:
chart = frappe.get_doc(‘Dashboard Chart’, chart_name)
chart = frappe._dict(frappe.parse_json(chart))
timespan = chart.timespan
timegrain = chart.time_interval
filters = frappe.parse_json(chart.filters_json)

account = filters.get(“account”)
company = filters.get(“company”)

if not to_date:
to_date = nowdate()
if not from_date:
if timegrain in (‘Daily’,‘Weekly’,‘Monthly’, ‘Quarterly’):
from_date = get_from_date_from_timespan(to_date, timespan)

fetch dates to plot

dates = get_dates_from_timegrain(from_date, to_date, timegrain)

Get balances on for set dates

receivable = []
for date in dates:
sql_query_str = ‘’‘SELECT sum(debit)-sum(credit) FROM tabGL Entry WHERE company="{0}" AND party_type=“Customer” AND posting_date<="{1}"’’’.format(company,date)
sql_query = frappe.db.sql(sql_query_str)
if sql_query[0][0]==None:
payable = []
for date in dates:
sql_query_str = ‘’‘SELECT (sum(debit)-sum(credit))*-1 FROM tabGL Entry WHERE company="{0}" AND party_type=“Supplier” AND posting_date<="{1}"’’’.format(company,date)
sql_query = frappe.db.sql(sql_query_str)
if sql_query[0][0]==None:

return {
“labels”: [ date for date in dates ],
“datasets”: [{
“name”: ‘Receivable’,
“values”: receivable
“name”: ‘Payable’,
“values”: payable

def get_dates_from_timegrain(from_date, to_date, timegrain):
days = months = years = 0
if “Daily” == timegrain:
days = 1
elif “Weekly” == timegrain:
days = 7
elif “Monthly” == timegrain:
months = 1
elif “Quarterly” == timegrain:
months = 3

dates = [get_period_ending(from_date, timegrain)]
while getdate(dates[-1]) < getdate(to_date):
date = get_period_ending(add_to_date(dates[-1], years=years, months=months, days=days), timegrain)
return dates