当前位置: 首页>>代码示例>>Python>>正文


Python graph_models.MultiBarChart类代码示例

本文整理汇总了Python中corehq.apps.reports.graph_models.MultiBarChart的典型用法代码示例。如果您正苦于以下问题:Python MultiBarChart类的具体用法?Python MultiBarChart怎么用?Python MultiBarChart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MultiBarChart类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_chart

 def get_chart(self, rows, columns, x_label, y_label):
     chart = MultiBarChart('% of Groups Receiving Grades', x_axis=Axis(x_label), y_axis=Axis(y_label, '.0%'))
     chart.height = 400
     chart.rotateLabels = -60
     chart.marginBottom = 90
     chart.marginLeft = 100
     self._chart_data(chart, columns, rows)
     return [chart]
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:8,代码来源:table_card_report.py

示例2: get_chart

    def get_chart(self, rows, x_label, y_label, data_provider):
        def _get_label_with_percentage(row):
            return "%s [%s%%]" % (row[0]['html'], str(int(row[-1]['html'][:-1])))

        if isinstance(data_provider, NutritionBirthWeightDetails):
            chart = PieChart('BirthWeight', '',
                             [{'label': "%s [%s%%]" % (row[0]['html'], str(int(row[-1]['html'][:-1]))),
                               'value': int(row[-1]['html'][:-1])} for row in rows[2:]], ['red', 'green'])
            chart.showLabels = False
        elif isinstance(data_provider, DeliveryPlaceDetailsExtended):
            chart = PieChart('', '', [{'label': _get_label_with_percentage(row),
                                       'value': int(row[-1]['html'][:-1])} for row in rows[1:]])
            chart.showLabels = False
        elif isinstance(data_provider, (PostnatalCareOverview, ImmunizationOverview)):
            chart = MultiBarChart('', x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart.rotateLabels = -45
            chart.marginBottom = 120
            if isinstance(data_provider, ImmunizationOverview):
                chart.stacked = True
                chart.add_dataset('Percentage',
                                  [{'x': row[0]['html'],
                                    'y': int(row[3]['html'][:-1]) / 100.0} for row in rows],
                                  color='green')
                chart.add_dataset('Dropout Percentage',
                                  [{'x': row[0]['html'],
                                    'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows],
                                  color='red')
            else:
                chart.add_dataset('Percentage',
                                  [{'x': row[0]['html'], 'y':int(row[-1]['html'][:-1]) / 100.0} for row in rows])
        elif isinstance(data_provider, AnteNatalCareServiceOverviewExtended):
            chart1 = MultiBarChart('', x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart2 = MultiBarChart('', x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart1.rotateLabels = -45
            chart2.rotateLabels = -45
            chart1.marginBottom = 120
            chart2.marginBottom = 120
            chart1.add_dataset('Percentage', [{'x': row[0]['html'],
                                               'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows[1:6]])
            chart2.add_dataset('Percentage', [{'x': row[0]['html'],
                                               'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows[6:12]])
            return [chart1, chart2]
        elif isinstance(data_provider, ChildrenDeathsByMonth):
            chart = LineChart('Seasonal Variation of Child Deaths', x_axis=Axis(x_label, dateFormat="%B"),
                              y_axis=Axis(y_label, '.2%'))
            chart.rotateLabels = -45
            chart.marginBottom = 120
            months_mapping = dict((v, k) for k, v in enumerate(calendar.month_abbr))
            chart.add_dataset('Percentage', [{'x': datetime.date(1, months_mapping[row[0][:3]], 1),
                                              'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows])
        else:
            chart = PieChart('', '', [{'label': "%s [%s%%]" % (row[0]['html'], str(int(row[-1]['html'][:-1]))),
                                       'value': int(row[-1]['html'][:-1])} for row in rows])
            chart.showLabels = False
        return [chart]
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:55,代码来源:__init__.py

示例3: get_chart

    def get_chart(self, rows, columns, x_label, y_label, has_total_column=False):

        end = len(columns)
        if has_total_column:
            end -= 1
        categories = [c.html for c in columns.header[1:end]]
        chart = MultiBarChart('', x_axis=Axis(x_label), y_axis=Axis(y_label, ' ,d'))
        chart.rotateLabels = -45
        chart.marginBottom = 120
        self._chart_data(chart, categories, rows)
        return [chart]
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:11,代码来源:tableu_de_board_report.py

示例4: get_chart

 def get_chart(self, rows, x_label, y_label):
     chunks = _chunks(list(rows), self.chunk_size + 1)
     charts = []
     if self.request.GET.get('group_by', '') == 'domain':
         chunks = sorted(chunks, key=lambda k: k[0][0])
     for chunk in chunks:
         chart = MultiBarChart(chunk[0][0], x_axis=Axis(x_label), y_axis=Axis(y_label, '.0%'))
         chart.height = 300
         chart.rotateLabels = 0
         chart.marginBottom = 80
         chart.marginLeft = 100
         self._chart_data(chart, chunk[1:])
         charts.append(chart)
     return charts
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:14,代码来源:adoption_disaggregated_report.py

示例5: get_chart

 def get_chart(self, rows, columns, x_label, y_label, has_total_column=False):
     """
     Get a MultiBarChart model for the given set of rows and columns.
     :param rows: 2D list of report data. Assumes index 0 of each row is the row label
     :param columns: list of DatabaseColumn objects
     """
     end = len(columns)
     if has_total_column:
         end -= 1
     categories = [c.data_tables_column.html for c in columns[1:end]]
     chart = MultiBarChart('', x_axis=Axis(x_label), y_axis=Axis(y_label, ' ,d'))
     chart.rotateLabels = -45
     chart.marginBottom = 120
     self._chart_data(chart, categories, rows)
     return [chart]
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:15,代码来源:reports.py

示例6: charts

    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]
开发者ID:jmaina,项目名称:commcare-hq,代码行数:29,代码来源:mixins.py

示例7: get_chart

 def get_chart(self, rows, columns, x_label, y_label):
     chart = MultiBarChart('Adoption of Practices', x_axis=Axis(x_label), y_axis=Axis(y_label))
     chart.forceY = [0, 100]
     chart.height = 700
     chart.rotateLabels = -55
     chart.marginBottom = 390
     chart.marginLeft = 350
     self._chart_data(chart, columns, rows)
     return [chart]
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:9,代码来源:adoption_bar_char_report.py

示例8: get_chart

    def get_chart(self, rows, x_label, y_label):
        chunks = _chunks(list(rows), self.chunk_size+1)
        charts = []
        for chunk in chunks:

            chart = MultiBarChart(chunk[0][0], x_axis=Axis(x_label), y_axis=Axis(y_label))
            chart.forceY = [0, 100]
            chart.height = 300
            chart.rotateLabels = 0
            chart.marginBottom = 80
            chart.marginLeft = 100
            self._chart_data(chart, chunk[1:])
            charts.append(chart)
        return charts
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:14,代码来源:adoption_disaggregated_report.py

示例9: charts

 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]
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:18,代码来源:sql_reports.py

示例10: charts

 def charts(self):
     if 'location_id' in self.request.GET: # hack: only get data if we're loading an actual report
         chart = MultiBarChart(None, Axis(_('Products')), Axis(_('% of Facilities'), ',.1d'))
         chart.data = self.get_data_for_graph()
         return [chart]
开发者ID:jmaina,项目名称:commcare-hq,代码行数:5,代码来源:standard.py

示例11: get_chart

    def get_chart(self, rows, x_label, y_label, data_provider):
        def _get_label_with_percentage(row):
            return "%s [%d: %s%%]" % (row[0]['html'], int(row[-2]['html']), str(int(row[-1]['html'][:-1])))

        if isinstance(data_provider, NutritionBirthWeightDetails):
            chart = PieChart(data_provider.chart_title, '',
                             [{'label': _get_label_with_percentage(row),
                               'value': int(row[-1]['html'][:-1])} for row in rows[2:]], ['red', 'green'])
            chart.showLabels = False
            chart.marginLeft = 20
            chart.marginRight = 0
            chart.marginBottom = 20
        elif isinstance(data_provider, DeliveryPlaceDetailsExtended):
            chart = PieChart(data_provider.chart_title, '',
                             [{'label': _get_label_with_percentage(row),
                               'value': int(row[-1]['html'][:-1])} for row in rows[1:]])
            chart.showLabels = False
        elif isinstance(data_provider, (PostnatalCareOverview, ImmunizationOverview)):
            chart = MultiBarChart(data_provider.chart_title, x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart.rotateLabels = -45
            chart.marginBottom = 150
            chart.marginLeft = 45
            chart.marginRight = 0

            if isinstance(data_provider, ImmunizationOverview):
                chart.stacked = True
                chart.add_dataset('Percentage',
                                  [{'x': row[0]['html'],
                                    'y': int(row[3]['html'][:-1]) / 100.0} for row in rows],
                                  color='green')
                chart.add_dataset('Dropout Percentage',
                                  [{'x': row[0]['html'],
                                    'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows],
                                  color='red')
            else:
                chart.add_dataset('Percentage',
                                  [{'x': row[0]['html'], 'y':int(row[-1]['html'][:-1]) / 100.0} for row in rows])
        elif isinstance(data_provider, AnteNatalCareServiceOverviewExtended):
            chart1 = MultiBarChart('ANC Visits', x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart2 = MultiBarChart('Maternal TT & IFA', x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart1.rotateLabels = -45
            chart2.rotateLabels = -45
            chart1.marginBottom = 150
            chart2.marginBottom = 150
            chart1.marginLeft = 20
            chart2.marginLeft = 45
            chart1.marginRight = 0
            chart2.marginRight = 0

            chart1.add_dataset('Percentage', [{'x': row[0]['html'],
                                               'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows[1:6]])
            chart2.add_dataset('Percentage', [{'x': row[0]['html'],
                                               'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows[6:12]])
            return [chart1, chart2]
        elif isinstance(data_provider, ChildrenDeathsByMonth):
            chart = MultiBarChart(data_provider.chart_title, x_axis=Axis(x_label, dateFormat="%B"),
                                  y_axis=Axis(y_label, '.2%'))
            chart.rotateLabels = -45
            chart.marginBottom = 50
            chart.marginLeft = 20
            chart.add_dataset('Percentage', [{'x': row[0],
                                              'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows])
        else:
            chart = PieChart(data_provider.chart_title, '', [{'label': _get_label_with_percentage(row),
                                                              'value': int(row[-1]['html'][:-1])} for row in rows])
            chart.showLabels = False
            chart.marginLeft = 20
            chart.marginRight = 0
            chart.marginBottom = 0
        return [chart]
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:70,代码来源:__init__.py

示例12: charts

    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)
            },
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例13: get_chart

    def get_chart(self, rows, columns, x_label, y_label):
        chart = MultiBarChart('Adoption of Practices', x_axis=Axis(x_label), y_axis=Axis(y_label, '%'))

        if self.report_config['group'] == 'domain':
            chart.height = 550
            chart.rotateLabels = -55
            chart.marginBottom = 250
        elif self.report_config['group'] == 'practice':
            chart.height = 700
            chart.rotateLabels = -55
            chart.marginBottom = 400
        else:
            chart.height = 320
            chart.rotateLabels = 0
            chart.marginBottom = 50

        chart.marginLeft = 200
        chart.marginRight = 150
        self._chart_data(chart, columns, rows)
        return [chart]
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:20,代码来源:adoption_bar_char_report.py

示例14: get_chart

    def get_chart(self, rows, x_label, y_label, data_provider):
        def _get_label_with_percentage(row):
            return "%s [%d: %s%%]" % (row[0]["html"], int(row[-2]["html"]), str(int(row[-1]["html"][:-1])))

        if isinstance(data_provider, NutritionBirthWeightDetails):
            chart = PieChart(
                data_provider.chart_title,
                "",
                [{"label": _get_label_with_percentage(row), "value": int(row[-1]["html"][:-1])} for row in rows[2:]],
                ["red", "green"],
            )
            chart.showLabels = False
            chart.marginLeft = 20
            chart.marginRight = 0
            chart.marginBottom = 20
        elif isinstance(data_provider, DeliveryPlaceDetailsExtended):
            chart = PieChart(
                data_provider.chart_title,
                "",
                [{"label": _get_label_with_percentage(row), "value": int(row[-1]["html"][:-1])} for row in rows[1:]],
            )
            chart.showLabels = False
        elif isinstance(data_provider, (PostnatalCareOverview, ImmunizationOverview)):
            chart = MultiBarChart(data_provider.chart_title, x_axis=Axis(x_label), y_axis=Axis(y_label, ".2%"))
            chart.rotateLabels = -45
            chart.marginBottom = 150
            chart.marginLeft = 45
            chart.marginRight = 0

            if isinstance(data_provider, ImmunizationOverview):
                chart.stacked = True
                chart.add_dataset(
                    "Percentage",
                    [{"x": row[0]["html"], "y": int(row[3]["html"][:-1]) / 100.0} for row in rows],
                    color="green",
                )
                chart.add_dataset(
                    "Dropout Percentage",
                    [{"x": row[0]["html"], "y": int(row[-1]["html"][:-1]) / 100.0} for row in rows],
                    color="red",
                )
            else:
                chart.add_dataset(
                    "Percentage", [{"x": row[0]["html"], "y": int(row[-1]["html"][:-1]) / 100.0} for row in rows]
                )
        elif isinstance(data_provider, AnteNatalCareServiceOverviewExtended):
            chart1 = MultiBarChart("ANC Visits", x_axis=Axis(x_label), y_axis=Axis(y_label, ".2%"))
            chart2 = MultiBarChart("Maternal TT & IFA", x_axis=Axis(x_label), y_axis=Axis(y_label, ".2%"))
            chart1.rotateLabels = -45
            chart2.rotateLabels = -45
            chart1.marginBottom = 150
            chart2.marginBottom = 150
            chart1.marginLeft = 20
            chart2.marginLeft = 45
            chart1.marginRight = 0
            chart2.marginRight = 0

            chart1.add_dataset(
                "Percentage", [{"x": row[0]["html"], "y": int(row[-1]["html"][:-1]) / 100.0} for row in rows[1:6]]
            )
            chart2.add_dataset(
                "Percentage", [{"x": row[0]["html"], "y": int(row[-1]["html"][:-1]) / 100.0} for row in rows[6:12]]
            )
            return [chart1, chart2]
        elif isinstance(data_provider, ChildrenDeathsByMonth):
            chart = MultiBarChart(
                data_provider.chart_title, x_axis=Axis(x_label, dateFormat="%B"), y_axis=Axis(y_label, ".2%")
            )
            chart.rotateLabels = -45
            chart.marginBottom = 50
            chart.marginLeft = 20
            chart.add_dataset("Percentage", [{"x": row[0], "y": int(row[-1]["html"][:-1]) / 100.0} for row in rows])
        else:
            chart = PieChart(
                data_provider.chart_title,
                "",
                [{"label": _get_label_with_percentage(row), "value": int(row[-1]["html"][:-1])} for row in rows],
            )
            chart.showLabels = False
            chart.marginLeft = 20
            chart.marginRight = 0
            chart.marginBottom = 0
        return [chart]
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:83,代码来源:__init__.py


注:本文中的corehq.apps.reports.graph_models.MultiBarChart类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。