本文整理汇总了Python中corehq.apps.reports.graph_models.MultiBarChart.stacked方法的典型用法代码示例。如果您正苦于以下问题:Python MultiBarChart.stacked方法的具体用法?Python MultiBarChart.stacked怎么用?Python MultiBarChart.stacked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.reports.graph_models.MultiBarChart
的用法示例。
在下文中一共展示了MultiBarChart.stacked方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: charts
# 需要导入模块: from corehq.apps.reports.graph_models import MultiBarChart [as 别名]
# 或者: from corehq.apps.reports.graph_models.MultiBarChart import stacked [as 别名]
def charts(self):
product_dashboard = ProductAvailabilityDashboardChart()
product_availability = self.rows
def convert_product_data_to_stack_chart(rows, chart_config):
ret_data = []
for k in ['Stocked out', 'Not Stocked out', 'No Stock Data']:
datalist = []
for product in rows:
prd_code = SQLProduct.objects.get(product_id=product.product).code
if k == 'No Stock Data':
datalist.append([prd_code, product.without_data])
elif k == 'Stocked out':
datalist.append([prd_code, product.without_stock])
elif k == 'Not Stocked out':
datalist.append([prd_code, product.with_stock])
ret_data.append({'color': chart_config.label_color[k], 'label': k, 'data': datalist})
return ret_data
chart = MultiBarChart('', x_axis=Axis('Products'), y_axis=Axis(''))
chart.rotateLabels = -45
chart.marginBottom = 120
chart.stacked = self.chart_stacked
for row in convert_product_data_to_stack_chart(product_availability, product_dashboard):
chart.add_dataset(row['label'], [
{'x': r[0], 'y': r[1]}
for r in sorted(row['data'], key=lambda x: x[0])], color=row['color']
)
return [chart]
示例2: charts
# 需要导入模块: from corehq.apps.reports.graph_models import MultiBarChart [as 别名]
# 或者: from corehq.apps.reports.graph_models.MultiBarChart import stacked [as 别名]
def charts(self):
rows = self.rows
loc_axis = Axis(label="Location")
tests_axis = Axis(label="Number of Tests", format=",.1d")
chart = MultiBarChart("Number of Tests Per Location", loc_axis, tests_axis)
chart.stacked = True
chart.tooltipFormat = " in "
chart.add_dataset(
"Male Tests",
[{'x':row[-10], 'y':row[-9]['html'] if row[-9] != "--" else 0} for row in rows],
color="#0006CE"
)
chart.add_dataset(
"Female Tests",
[{'x':row[-10], 'y':row[-8]['html'] if row[-8] != "--" else 0} for row in rows],
color="#70D7FF"
)
return [chart]
示例3: charts
# 需要导入模块: from corehq.apps.reports.graph_models import MultiBarChart [as 别名]
# 或者: from corehq.apps.reports.graph_models.MultiBarChart import stacked [as 别名]
def charts(self):
case_finding_sql_data = self.case_finding_sql_data[0]
sputum_conversion_report = ReportFactory.from_spec(
StaticReportConfiguration.by_id('static-%s-sputum_conversion' % self.domain), include_prefilters=True
)
filter_values = {'date': QuarterFilter.get_value(self.request, self.domain)}
locations_id = [
Choice(value=location_id, display='') for location_id in self.report_config.locations_id
if location_id
]
if locations_id:
filter_values['village'] = locations_id
sputum_conversion_report.set_filter_values(filter_values)
sputum_conversion_data = sputum_conversion_report.get_data()[0]
charts_sql_data = self.charts_sql_data[0]
treatment_outcome_sql_data = self.treatment_outcome_sql_data[0]
default_value = {'sort_key': 0}
chart = PieChart(title=_('Cases by Gender'), key='gender', values=[])
chart.data = [
{'label': _('Male'), 'value': case_finding_sql_data.get('male_total', default_value)['sort_key']},
{
'label': _('Female'),
'value': case_finding_sql_data.get('female_total', default_value)['sort_key']
},
{
'label': _('Transgender'),
'value': case_finding_sql_data.get('transgender_total', default_value)['sort_key']
}
]
chart2 = MultiBarChart(_('Cases By Type'), x_axis=Axis(''), y_axis=Axis(''))
chart2.stacked = False
chart2.showLegend = False
positive_smear = case_finding_sql_data.get('new_positive_tb_pulmonary', default_value)['sort_key']
negative_smear = case_finding_sql_data.get('new_negative_tb_pulmonary', default_value)['sort_key']
positive_extra_pulmonary = case_finding_sql_data.get(
'new_positive_tb_extrapulmonary', default_value
)['sort_key']
relapse_cases = case_finding_sql_data.get('recurrent_positive_tb', default_value)['sort_key']
failure_cases = case_finding_sql_data.get('failure_positive_tb', default_value)['sort_key']
lfu_cases = case_finding_sql_data.get('lfu_positive_tb', default_value)['sort_key']
others_cases = case_finding_sql_data.get('others_positive_tb', default_value)['sort_key']
chart2.add_dataset(
_('New'),
[
{'x': 'Smear +ve', 'y': positive_smear},
{'x': 'Smear -ve', 'y': negative_smear},
{'x': 'EP', 'y': positive_extra_pulmonary}
]
)
chart2.add_dataset(
_('Retreatment'), [
{'x': 'Relapse', 'y': relapse_cases},
{'x': 'Failure', 'y': failure_cases},
{'x': 'Treatment After Default', 'y': lfu_cases},
{'x': 'Others', 'y': others_cases}
]
)
chart3 = MultiBarChart('Sputum Conversion By Patient Type', Axis(''), Axis(''))
chart3.stacked = True
chart3.add_dataset('Positive', [
{
'x': _('New Sputum +ve (2 month IP)'),
'y': sputum_conversion_data.get('new_sputum_positive_patient_2months_ip', 0)
},
{
'x': _('New Sputum +ve (3 month IP)'),
'y': sputum_conversion_data.get('new_sputum_positive_patient_3months_ip', 0)
},
{
'x': _('Cat II (3 month IP)'),
'y': sputum_conversion_data.get('positive_endofip_patients_cat2', 0)
},
])
chart3.add_dataset(_('Negative'), [
{
'x': _('New Sputum +ve (2 month IP)'),
'y': sputum_conversion_data.get('new_sputum_negative_patient_2months_ip', 0)
},
{
'x': _('New Sputum +ve (3 month IP)'),
'y': sputum_conversion_data.get('new_sputum_negative_patient_3months_ip', 0)
},
{
'x': _('Cat II (3 month IP)'),
'y': sputum_conversion_data.get('negative_endofip_patients_cat2', 0)
},
#.........这里部分代码省略.........