def get_echarts_instance(self, *args, **kwargs): self.hasresult = False self.keyword = self.request.GET.get('q') print('keyword = {}'.format(self.keyword)) if not self.keyword: return None # print(bar.__class__) # cur.execute('select id, address, production_unit_name from production_units where production_unit_name like %s', '%四川%') self.cur.execute("select res.year, count(*) as counts from \ (select drug_name_zh, date_format(approval_date, '%Y') as year from drugs_approved where drug_name_zh like '{}') as res \ group by res.drug_name_zh, res.year".format(self.keyword)) # cur.execute("select drug_name_zh, date_format(approval_date, '%Y') as year from drugs_approved where drug_name_zh like '%氯化钠注射液%'") result = self.cur.fetchall() print('result = {}'.format(result)) echarts_instance = NamedCharts() if not result: return None self.hasresult = True ds, hs = zip(*result) bar = Bar(self.keyword, "这里是副标题") bar.add(self.keyword, ds, hs) bar.add('copy', ds, hs) echarts_instance = echarts_instance.add_chart(bar, name='pieo') bar2 = Bar("我的第2个图表", "这里是副标题") # print(bar2.__class__) bar2.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90]) echarts_instance = echarts_instance.add_chart(bar2, name='piet') return echarts_instance
def test_create_with_kwargs(self): nc = NamedCharts(bar=MockChart('Bar Chart'), line=MockChart('Line Chart')) nc.add_chart(MockChart('Map Chart'), name='map') self.assertEqual('Bar Chart', nc['bar'].page_title) self.assertListEqual(['Bar Chart', 'Line Chart', 'Map Chart'], [c.page_title for c in nc])
def get_echarts_instance(self, *arg, **kwargs): if len(self.dataset) > 0: self.hasresult = True bar = Bar(self.cur_word, "按别名") # aggregate data count of each name from db, then order them ys, cs = zip(*self.dataset) bar.add(self.cur_word, ys, cs) print('bar = {}'.format(bar)) echarts_instance = NamedCharts() echarts_instance = echarts_instance.add_chart(bar) return echarts_instance
def get_echarts_instance(self, *args, **kwargs): device_data = models.Device.objects.values('device_type').annotate(count=Count('device_type')) device_types, counters = fetch(device_data, 'device_type', 'count') pie = Pie("设备分类", page_title='设备分类', width='100%') pie.add("设备分类", device_types, counters, is_label_show=True) battery_lifes = models.Device.objects.values('name', 'battery_life') names, lifes = fetch(battery_lifes, 'name', 'battery_life') bar = Bar('设备电量', page_title='设备电量', width='100%') bar.add("设备电量", names, lifes) charts = NamedCharts().add_chart(pie, name='pie').add_chart(bar, name='bar') return charts
def test_create_with_kwargs(self): nc = NamedCharts().add_chart( MockChart('Line Chart'), name='line').add_chart( MockChart('Bar Chart')).add_chart(MockChart('Map Chart'), name='map') self.assertEqual('Line Chart', nc['line'].page_title) self.assertEqual('Bar Chart', nc['c1'].page_title) self.assertListEqual(['Line Chart', 'Bar Chart', 'Map Chart'], [c.page_title for c in nc]) with self.assertRaises(KeyError): c = nc['no_charts'] print(c.page_title) self.assertEqual('Bar Chart', nc[1].page_title)