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


Python SimpleLineChart.set_line_style方法代码示例

本文整理汇总了Python中pygooglechart.SimpleLineChart.set_line_style方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleLineChart.set_line_style方法的具体用法?Python SimpleLineChart.set_line_style怎么用?Python SimpleLineChart.set_line_style使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygooglechart.SimpleLineChart的用法示例。


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

示例1: group

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
def group(request, group_id):
    group = get_object_or_404(GroupedMessage, pk=group_id)

    message_list = group.message_set.all()
    
    obj = message_list.order_by('-id')[0]
    if '__sentry__' in obj.data:
        module, args, frames = obj.data['__sentry__']['exc']
        obj.class_name = str(obj.class_name)
        # We fake the exception class due to many issues with imports/builtins/etc
        exc_type = type(obj.class_name, (Exception,), {})
        exc_value = exc_type(obj.message)

        exc_value.args = args
    
        reporter = ImprovedExceptionReporter(obj.request, exc_type, exc_value, frames, obj.data['__sentry__'].get('template'))
        traceback = mark_safe(reporter.get_traceback_html())
    elif group.traceback:
        traceback = mark_safe('<pre>%s</pre>' % (group.traceback,))
    
    unique_urls = message_list.filter(url__isnull=False).values_list('url', 'logger', 'view', 'checksum').annotate(times_seen=Count('url')).values('url', 'times_seen').order_by('-times_seen')
    
    unique_servers = message_list.filter(server_name__isnull=False).values_list('server_name', 'logger', 'view', 'checksum').annotate(times_seen=Count('server_name')).values('server_name', 'times_seen').order_by('-times_seen')

    def iter_data(obj):
        for k, v in obj.data.iteritems():
            if k.startswith('_') or k in ['url']:
                continue
            yield k, v
    
    json_data = iter_data(obj)
    
    # TODO: this should be a template tag
    engine = get_db_engine()
    if SimpleLineChart and not engine.startswith('sqlite'):
        today = datetime.datetime.now()

        chart_qs = message_list\
                          .filter(datetime__gte=today - datetime.timedelta(hours=24))\
                          .extra(select={'hour': 'extract(hour from datetime)'}).values('hour')\
                          .annotate(num=Count('id')).values_list('hour', 'num')

        rows = dict(chart_qs)
        if rows:
            max_y = max(rows.values())
        else:
            max_y = 1

        chart = SimpleLineChart(300, 80, y_range=[0, max_y])
        chart.add_data([max_y]*30)
        chart.add_data([rows.get((today-datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
        chart.add_data([0]*30)
        chart.fill_solid(chart.BACKGROUND, 'eeeeee')
        chart.add_fill_range('eeeeee', 0, 1)
        chart.add_fill_range('e0ebff', 1, 2)
        chart.set_colours(['eeeeee', '999999', 'eeeeee'])
        chart.set_line_style(1, 1)
        chart_url = chart.get_url()
    
    return render_to_response('sentry/group/details.html', locals())
开发者ID:texastribune,项目名称:django-sentry,代码行数:62,代码来源:views.py

示例2: _partyline

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
    def _partyline(self, party_results):
        if self.request.GET.get('percentages') == 'true':
            key = 'percentage'
        else:
            key = 'count'

        maxcount = 0
        allcounts = []
        granularity = self.request.GET.get('granularity')
        months = []

        for party, results in party_results.iteritems():
            counts = [x.get(key) for x in results['results']]
            allcounts.append(counts)
            if max(counts) > maxcount:
                maxcount = max(counts)

            if granularity == 'month':
                months = [x['month'] for x in results['results']]
                januaries = [x for x in months if x.endswith('01')]
                january_indexes = [months.index(x) for x in januaries]
                january_percentages = [int((x / float(len(months))) * 100) for x in january_indexes]

            #times = [x.get(granularity) for x in results['results']]

        width = int(self.request.GET.get('width', 575))
        height = int(self.request.GET.get('height', 318))
        chart = SimpleLineChart(width, height, y_range=(0, max(counts)))

        chart.fill_solid('bg', '00000000')  # Make the background transparent
        chart.set_grid(0, 50, 2, 5)  # Set gridlines

        if granularity == 'month':
            index = chart.set_axis_labels(Axis.BOTTOM, [x[:4] for x in januaries[::2]])
            chart.set_axis_positions(index, [x for x in january_percentages[::2]])

        if key == 'percentage':
            label = '%.4f' % maxcount
        else:
            label = int(maxcount)
        index = chart.set_axis_labels(Axis.LEFT, [label, ])
        chart.set_axis_positions(index, [100, ])

        for n, counts in enumerate(allcounts):
            chart.add_data(counts)
            chart.set_line_style(n, thickness=2)  # Set line thickness

        colors = {'R': 'bb3110', 'D': '295e72', }
        chart_colors = []
        chart_legend = []
        for k in party_results.keys():
            chart_colors.append(colors.get(k, '000000'))
            chart_legend.append(k)
            chart.legend_position = 'b'

        chart.set_colours(chart_colors)

        if self.request.GET.get('legend', 'true') != 'false':
            chart.set_legend(chart_legend)
        return chart.get_url()
开发者ID:notthatbreezy,项目名称:Capitol-Words,代码行数:62,代码来源:views.py

示例3: get

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
	def get(self):
		query1 = self.request.get('query1');
		query2 = self.request.get('query2');
		if query2 == '':
			 query2 = query1;
		self.response.headers['Content-Type'] = 'text/html; charset=UTF-8'
		self.response.out.write(HTML_TEMPLATE % {'query1' : query1.replace('"','&quot;'), 'query2' : query2.replace('"','&quot;')})
		if query1 != None and query2 != None:
			year_07 = '%s publication_year:[2008]' %  query1
			year_08 = '%s publication_year:[2008]' %  query2
			results7 = search(year_07)
			results8 = search(year_08)
			data7 = extract(results7)
			data8 = extract(results8)
			if sum(data8) == 0:
				data8 = [1] * 12
			big = max(data7 + data8)
			small = min(data7 + data8)
			chart = SimpleLineChart(600,400,y_range=[ small, big])
			chart.add_data(data7)
			chart.add_data(data8)
			chart.set_colours(['207000','0077A0'])
			chart.set_axis_labels(Axis.LEFT,range(small,big,((big-small+1)/ 12)+1)) 
			chart.set_axis_labels(Axis.BOTTOM,[ x[:3] for x in calendar.month_name ][1:])
			chart.set_line_style(0,thickness=6)
			chart.set_line_style(1,thickness=6)
			self.response.out.write('<div id="container">') 
			self.response.out.write('<div id="graph">') 
			self.response.out.write('<h2>Trend <font color="207000">%s</font> vs. <font color="0077A0">%s</font> for 2008</h2>' % (query1,query2))
			self.response.out.write('<img src="%s">' % chart.get_url() )
			self.response.out.write('<strong>Total: <font color="207000">%s</font> %d</strong> &nbsp; ' %(query1,results7['total']))
			self.response.out.write('<strong><font color="0077A0">%s</font> %d</strong>' % (query2,results8['total']))
			self.response.out.write('<br>As mentioned in articles from <a href="http://www.nytimes.com">The New York Times</a>')
			self.response.out.write('</div')
			self.response.out.write('<div id="img"><center>')
			self.response.out.write('<h2><font color="207000">%s</font></h2>'% (query1))
			for i in results7['results']:
				if 'small_image_url' in i: 
					self.response.out.write('<a href="%s"><img src="%s"></a>' % (i['url'],i['small_image_url']))
			self.response.out.write('</center></div>')
			self.response.out.write('<div id="img"><center>')
			self.response.out.write('<h2><font color="0077A0">%s</font></h2>'% (query2))
			for i in results8['results']:
				if 'small_image_url' in i: 
					self.response.out.write('<a href="%s"><img src="%s"></a>' % (i['url'],i['small_image_url']))
			self.response.out.write('</center></div>')
			self.response.out.write('</div>')
		self.response.out.write('<div id="container">brought to you via the search api of <a href="http://developer.nytimes.com">nytimes.com</a> and <a href="http://twitter.com/derekg">derekg</a></div>')
		self.response.out.write('</center></body></html>')
开发者ID:GunioRobot,项目名称:nyt-trender,代码行数:51,代码来源:search.py

示例4: _line

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
    def _line(self, results):
        key = 'count'
        if self.request.GET.get('percentages') == 'true':
            key = 'percentage'
        counts = [x.get(key) for x in results]
        maxcount = max(counts)

        granularity = self.request.GET.get('granularity')
        times = [x.get(granularity) for x in results]

        width = int(self.request.GET.get('width', 575))
        height = int(self.request.GET.get('height', 300))
        chart = SimpleLineChart(width, height, y_range=(0, max(counts)))
        chart.add_data(counts)
        chart.set_line_style(0, thickness=2)  # Set line thickness
        chart.set_colours(['E0B300', ])
        chart.fill_solid('bg', '00000000')  # Make the background transparent
        chart.set_grid(0, 50, 2, 5)  # Set gridlines

        if self.request.GET.get('granularity') == 'month':
            months = [x['month'] for x in results]
            januaries = [x for x in months if x.endswith('01')]
            january_indexes = [months.index(x) for x in januaries]
            january_percentages = [int((x / float(len(months))) * 100) for x in january_indexes]
            index = chart.set_axis_labels(Axis.BOTTOM, [x[:4] for x in januaries[::2]])
            chart.set_axis_positions(index, [x for x in january_percentages[::2]])

        if key == 'percentage':
            label = '%.4f' % maxcount
            label += '%'
        else:
            label = int(maxcount)
        index = chart.set_axis_labels(Axis.LEFT, [label, ])
        chart.set_axis_positions(index, [100, ])

        if self.request.GET.get('legend', 'true') != 'false':
            chart.set_legend([self.request.GET.get('phrase'), ])

        return chart.get_url()
开发者ID:notthatbreezy,项目名称:Capitol-Words,代码行数:41,代码来源:views.py

示例5: group_message_list

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
def group_message_list(request, group_id):
    group = get_object_or_404(GroupedMessage, pk=group_id)

    message_list = group.message_set.all().order_by('-datetime')
    
    unique_urls = message_list.filter(url__isnull=False).values_list('url', 'logger', 'view', 'checksum').annotate(times_seen=Count('url')).values('url', 'times_seen').order_by('-times_seen')
    
    unique_servers = message_list.filter(server_name__isnull=False).values_list('server_name', 'logger', 'view', 'checksum').annotate(times_seen=Count('server_name')).values('server_name', 'times_seen').order_by('-times_seen')
    
    engine = get_db_engine()
    if SimpleLineChart and not engine.startswith('sqlite'):
        today = datetime.datetime.now()

        chart_qs = message_list\
                          .filter(datetime__gte=today - datetime.timedelta(hours=24))\
                          .extra(select={'hour': 'extract(hour from datetime)'}).values('hour')\
                          .annotate(num=Count('id')).values_list('hour', 'num')

        rows = dict(chart_qs)
        if rows:
            max_y = max(rows.values())
        else:
            max_y = 1

        chart = SimpleLineChart(300, 80, y_range=[0, max_y])
        chart.add_data([max_y]*30)
        chart.add_data([rows.get((today-datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
        chart.add_data([0]*30)
        chart.fill_solid(chart.BACKGROUND, 'eeeeee')
        chart.add_fill_range('eeeeee', 0, 1)
        chart.add_fill_range('e0ebff', 1, 2)
        chart.set_colours(['eeeeee', '999999', 'eeeeee'])
        chart.set_line_style(1, 1)
        chart_url = chart.get_url()
    
    page = 'messages'
    
    return render_to_response('sentry/group/message_list.html', locals())
开发者ID:texastribune,项目名称:django-sentry,代码行数:40,代码来源:views.py

示例6: generate_mon_chart

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
def generate_mon_chart(mon_counts_1, mon_counts_2):
    """Generates a line graph plotting articles per month.

    Returns the url to a Google Chart showing the article counts in 
    mon_counts_1 vs. those in mon_counts_2.
    """
    # Get the first three letters of the calendar month names
    x_axis = [name[:3] for name in calendar.month_name][1:]
    min_y = min(mon_counts_1 + mon_counts_2)
    max_y = max(mon_counts_1 + mon_counts_2)
    step_y = ((max_y - min_y + 1) / 14) + 1
    y_axis = range(min_y, max_y, step_y)

    chart = SimpleLineChart(CHART_WIDTH, CHART_HEIGHT, y_range=[min_y, max_y])
    chart.add_data(mon_counts_1)
    chart.add_data(mon_counts_2)
    chart.set_colours([LINE_COLOR_1, LINE_COLOR_2])
    chart.set_axis_labels(Axis.BOTTOM, x_axis)
    chart.set_axis_labels(Axis.LEFT, y_axis)
    chart.set_line_style(0, thickness=LINE_THICKNESS)
    chart.set_line_style(1, thickness=LINE_THICKNESS)

    return chart.get_url()
开发者ID:baron314159,项目名称:nyt-trender,代码行数:25,代码来源:index.py

示例7: chart_url

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
def chart_url(group):
    today = datetime.datetime.now()

    chart_qs = group.message_set.all()\
                      .filter(datetime__gte=today - datetime.timedelta(hours=24))\
                      .extra(select={'hour': 'extract(hour from datetime)'}).values('hour')\
                      .annotate(num=Count('id')).values_list('hour', 'num')

    rows = dict(chart_qs)
    if rows:
        max_y = max(rows.values())
    else:
        max_y = 1

    chart = SimpleLineChart(300, 80, y_range=[0, max_y])
    chart.add_data([max_y]*30)
    chart.add_data([rows.get((today-datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
    chart.add_data([0]*30)
    chart.fill_solid(chart.BACKGROUND, 'eeeeee')
    chart.add_fill_range('eeeeee', 0, 1)
    chart.add_fill_range('e0ebff', 1, 2)
    chart.set_colours(['eeeeee', '999999', 'eeeeee'])
    chart.set_line_style(1, 1)
    return chart.get_url()
开发者ID:indro,项目名称:django-sentry,代码行数:26,代码来源:sentry_helpers.py

示例8: index

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
def index(request):
    logger_names = SortedDict((l, l) for l in GroupedMessage.objects.values_list("logger", flat=True).distinct())
    server_names = SortedDict((l, l) for l in Message.objects.values_list("server_name", flat=True).distinct())
    level_names = SortedDict((str(k), v) for k, v in LOG_LEVELS)

    logger = request.GET.get("logger")
    server_name = request.GET.get("server_name") or ""
    level = request.GET.get("level") or ""

    try:
        page = int(request.GET.get("p", 1))
    except (TypeError, ValueError):
        page = 1

    realtime = page == 1

    if logger not in logger_names:
        logger = ""

    if server_name not in server_names:
        server_name = ""

    if level not in level_names:
        level = ""

    # this only works in postgres
    message_list = (
        GroupedMessage.objects.filter(status=0)
        .extra(
            select={"score": "times_seen / (pow((floor(extract(epoch from now() - last_seen) / 3600) + 2), 1.25) + 1)"}
        )
        .order_by("-score", "-last_seen")
    )

    today = datetime.datetime.now()

    chart_qs = (
        Message.objects.filter(datetime__gte=today - datetime.timedelta(hours=24))
        .extra(select={"hour": "extract(hour from datetime)"})
        .values("hour")
        .annotate(num=Count("id"))
        .values_list("hour", "num")
    )

    if logger:
        message_list = message_list.filter(logger=logger)
        chart_qs = chart_qs.filter(logger=logger)

    if level:
        message_list = message_list.filter(level=level)
        chart_qs = chart_qs.filter(level=level)

    if server_name:
        message_list = message_list.filter(message_set__server_name=server_name).distinct()
        chart_qs = chart_qs.filter(server_name=server_name)

    rows = dict(chart_qs)
    if rows:
        max_y = max(rows.values())
    else:
        max_y = 1

    if SimpleLineChart:
        chart = SimpleLineChart(384, 80, y_range=[0, max_y])
        chart.add_data([max_y] * 30)
        chart.add_data([rows.get((today - datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
        chart.add_data([0] * 30)
        chart.fill_solid(chart.BACKGROUND, "eeeeee")
        chart.add_fill_range("eeeeee", 0, 1)
        chart.add_fill_range("e0ebff", 1, 2)
        chart.set_colours(["eeeeee", "999999", "eeeeee"])
        chart.set_line_style(1, 1)
        chart_url = chart.get_url()

    return render_to_response("sentry/index.html", locals())
开发者ID:justquick,项目名称:django-sentry,代码行数:77,代码来源:views.py

示例9: group

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
def group(request, group_id):
    group = GroupedMessage.objects.get(pk=group_id)

    message_list = group.message_set.all()

    obj = message_list[0]
    if "__sentry__" in obj.data:
        module, args, frames = obj.data["__sentry__"]["exc"]
        obj.class_name = str(obj.class_name)
        # We fake the exception class due to many issues with imports/builtins/etc
        exc_type = type(obj.class_name, (Exception,), {})
        exc_value = exc_type(obj.message)

        exc_value.args = args

        fake_request = FakeRequest()
        fake_request.META = obj.data.get("META", {})
        fake_request.GET = obj.data.get("GET", {})
        fake_request.POST = obj.data.get("POST", {})
        fake_request.FILES = obj.data.get("FILES", {})
        fake_request.COOKIES = obj.data.get("COOKIES", {})
        fake_request.url = obj.url
        if obj.url:
            fake_request.path_info = "/" + obj.url.split("/", 3)[-1]
        else:
            fake_request.path_info = ""

        reporter = ImprovedExceptionReporter(
            fake_request, exc_type, exc_value, frames, obj.data["__sentry__"].get("template")
        )
        traceback = mark_safe(reporter.get_traceback_html())
    else:
        traceback = mark_safe("<pre>%s</pre>" % (group.traceback,))

    unique_urls = (
        message_list.filter(url__isnull=False)
        .values_list("url", "logger", "view", "checksum")
        .annotate(times_seen=Count("url"))
        .values("url", "times_seen")
        .order_by("-times_seen")
    )

    unique_servers = (
        message_list.filter(server_name__isnull=False)
        .values_list("server_name", "logger", "view", "checksum")
        .annotate(times_seen=Count("server_name"))
        .values("server_name", "times_seen")
        .order_by("-times_seen")
    )

    today = datetime.datetime.now()

    chart_qs = (
        message_list.filter(datetime__gte=today - datetime.timedelta(hours=24))
        .extra(select={"hour": "extract(hour from datetime)"})
        .values("hour")
        .annotate(num=Count("id"))
        .values_list("hour", "num")
    )

    rows = dict(chart_qs)
    if rows:
        max_y = max(rows.values())
    else:
        max_y = 1

    if SimpleLineChart:
        chart = SimpleLineChart(384, 80, y_range=[0, max_y])
        chart.add_data([max_y] * 30)
        chart.add_data([rows.get((today - datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
        chart.add_data([0] * 30)
        chart.fill_solid(chart.BACKGROUND, "eeeeee")
        chart.add_fill_range("eeeeee", 0, 1)
        chart.add_fill_range("e0ebff", 1, 2)
        chart.set_colours(["eeeeee", "999999", "eeeeee"])
        chart.set_line_style(1, 1)
        chart_url = chart.get_url()

    return render_to_response("sentry/group.html", locals())
开发者ID:justquick,项目名称:django-sentry,代码行数:81,代码来源:views.py

示例10: _line_strip_graph

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
def _line_strip_graph(data, legends, axis_labels, size, steps, 
                           type=SimpleLineChart, multiline=False, **kwargs):
    if multiline:
        max_values = []
        min_values = [] 
        for row in data:
            max_values.append(max(row))
            min_values.append(min(row))
        max_y = max(max_values)
        min_y = min(min_values)
    else:
        max_y = max(data)
        min_y = min(data)
    
    #validando si hay datos para hacer grafico
    if max_y==0:
        return None

    chart = SimpleLineChart(size[0], size[1], y_range=[0, max_y*1.05])

    if multiline:
        for row in data:
            chart.add_data(row)
    else:
        chart.add_data(data)
    
    step = ((max_y*1.05)-(min_y*0.95))/steps

    #validando en caso de el paso sea menor que uno y de cero en la conversion
    if step<1:
        step = 1
    
    max_value = max_y
    tope = int(round(max_value*1.05))
    if tope < max_value:
        tope+=2
    else:
        tope+=1

    try:
        left_axis = range(int(round(min_y*0.95)), tope, int(step))
    except ValueError:
        #error por que los range no soportan decimales
        left_axis = range(0, 2)
    left_axis[0]=''

    chart.set_axis_range(Axis.LEFT, min_y, tope)
    if 'units' in kwargs:
        chart.set_axis_labels(Axis.LEFT, kwargs['units'])

    if 'time' in kwargs:
        chart.set_axis_labels(Axis.BOTTOM, kwargs['time'])

    chart.set_grid(0, 25, 4, 4,)
    chart.chls=4|4
    #chart.fill_linear_stripes(Chart.CHART, 0, 'FFFFEF', 0.2, 'FFFFFF', 0.2)
    chart.set_colours(COLORS)

    if axis_labels:
        chart.set_axis_labels(Axis.BOTTOM, axis_labels)
    chart.set_legend(legends)
    chart.set_legend_position('b')

    if 'thickness' in kwargs:
        if multiline:
            for i in range(len(data)):
                chart.set_line_style(index = i, thickness=kwargs['thickness'])
        else:
            chart.set_line_style(index=0, thickness=kwargs['thickness'])

    return chart
开发者ID:fitoria,项目名称:mcas,代码行数:73,代码来源:grafos.py

示例11: read

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
    def read(self, request, *args, **kwargs):
        self.request = request
        if kwargs.get('chart_type') == 'timeline':
            handler = PhraseOverTimeHandler()
            if request.GET.get('split_by_party') == 'true':
                resultsets = {}
                for party in ['R', 'D', ]:
                    kwargs['party'] = party
                    resultsets[party] = handler.read(request, *args, **kwargs)
                return {'results': {'url': self._partyline(resultsets), }, }

            elif request.GET.get('compare') == 'true':
                phrases = request.GET.get('phrases', '').split(',')[:5]  # Max of 5 phrases
                parties = request.GET.get('parties', '').split(',')
                states = request.GET.get('states', '').split(',')
                #chambers = request.GET.get('chambers', '').split(',')

                colors = ['8E2844', 'A85B08', 'AF9703', ]

                metadata = []
                legend_items = []
                months = None

                key = 'count'
                if self.request.GET.get('percentages') == 'true':
                    key = 'percentage'

                granularity = self.request.GET.get('granularity')

                width = int(request.GET.get('width', 575))
                height = int(request.GET.get('height', 300))
                chart = SimpleLineChart(width, height)
                chart.set_grid(0, 50, 2, 5)  # Set gridlines
                chart.fill_solid('bg', '00000000')  # Make the background transparent
                chart.set_colours(colors)
                maxcount = 0

                # Use phrases as a baseline; that is, assume that
                # there's a corresponding value for the other filters.
                # If a filter doesn't have as many values as the number
                # of phrases, the corresponding phrase will not be
                # filtered.
                # (However, if a value is set for 'party' or 'state'
                # in the querystring, that will override any values
                # set in 'phrases' or 'parties.')
                for n, phrase in enumerate(phrases):
                    chart.set_line_style(n, thickness=2)  # Set line thickness

                    if not phrase.strip():
                        continue
                    kwargs['phrase'] = phrase
                    legend = phrase
                    try:
                        kwargs['party'] = parties[n]
                    except IndexError:
                        pass

                    try:
                        kwargs['state'] = states[n]
                    except IndexError:
                        pass

                    if kwargs.get('party') and kwargs.get('state'):
                        legend += ' (%(party)s, %(state)s)' % kwargs
                    elif kwargs.get('party'):
                        legend += ' (%(party)s)' % kwargs
                    elif kwargs.get('state'):
                        legend += ' (%(state)s)' % kwargs

                    legend_items.append(legend)

                    data = handler.read(request, *args, **kwargs)
                    results = data['results']
                    counts = [x.get(key) for x in results]
                    if max(counts) > maxcount:
                        maxcount = max(counts)

                    chart.add_data(counts)
                    metadata.append(kwargs)

                # Duplicated code; should move into separate function.
                if self.request.GET.get('granularity') == 'month':
                    if not months:
                        months = [x['month'] for x in results]
                        januaries = [x for x in months if x.endswith('01')]
                        january_indexes = [months.index(x) for x in januaries]
                        january_percentages = [int((x / float(len(months))) * 100) for x in january_indexes]
                        index = chart.set_axis_labels(Axis.BOTTOM, [x[:4] for x in januaries[::2]])
                        chart.set_axis_positions(index, [x for x in january_percentages[::2]])

                chart.y_range = (0, maxcount)

                if key == 'percentage':
                    label = '%.4f' % maxcount
                    label += '%'
                else:
                    label = int(maxcount)

                index = chart.set_axis_labels(Axis.LEFT, [label, ])
                chart.set_axis_positions(index, [100, ])
#.........这里部分代码省略.........
开发者ID:notthatbreezy,项目名称:Capitol-Words,代码行数:103,代码来源:views.py

示例12: group

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]
def group(request, group_id):
    group = GroupedMessage.objects.get(pk=group_id)

    message_list = group.message_set.all()
    
    obj = message_list[0]
    if '__sentry__' in obj.data:
        module, args, frames = obj.data['__sentry__']['exc']
        obj.class_name = str(obj.class_name)
        # We fake the exception class due to many issues with imports/builtins/etc
        exc_type = type(obj.class_name, (Exception,), {})
        exc_value = exc_type(obj.message)

        exc_value.args = args
    
        fake_request = FakeRequest()
        fake_request.META = obj.data.get('META', {})
        fake_request.GET = obj.data.get('GET', {})
        fake_request.POST = obj.data.get('POST', {})
        fake_request.FILES = obj.data.get('FILES', {})
        fake_request.COOKIES = obj.data.get('COOKIES', {})
        fake_request.url = obj.url
        if obj.url:
            fake_request.path_info = '/' + obj.url.split('/', 3)[-1]
        else:
            fake_request.path_info = ''

        reporter = ImprovedExceptionReporter(fake_request, exc_type, exc_value, frames, obj.data['__sentry__'].get('template'))
        traceback = mark_safe(reporter.get_traceback_html())
    elif group.traceback:
        traceback = mark_safe('<pre>%s</pre>' % (group.traceback,))
    
    unique_urls = message_list.filter(url__isnull=False).values_list('url', 'logger', 'view', 'checksum').annotate(times_seen=Count('url')).values('url', 'times_seen').order_by('-times_seen')
    
    unique_servers = message_list.filter(server_name__isnull=False).values_list('server_name', 'logger', 'view', 'checksum').annotate(times_seen=Count('server_name')).values('server_name', 'times_seen').order_by('-times_seen')
    
    if SimpleLineChart:
        today = datetime.datetime.now()

        chart_qs = message_list\
                          .filter(datetime__gte=today - datetime.timedelta(hours=24))\
                          .extra(select={'hour': 'extract(hour from datetime)'}).values('hour')\
                          .annotate(num=Count('id')).values_list('hour', 'num')

        rows = dict(chart_qs)
        if rows:
            max_y = max(rows.values())
        else:
            max_y = 1

        chart = SimpleLineChart(300, 80, y_range=[0, max_y])
        chart.add_data([max_y]*30)
        chart.add_data([rows.get((today-datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
        chart.add_data([0]*30)
        chart.fill_solid(chart.BACKGROUND, 'eeeeee')
        chart.add_fill_range('eeeeee', 0, 1)
        chart.add_fill_range('e0ebff', 1, 2)
        chart.set_colours(['eeeeee', '999999', 'eeeeee'])
        chart.set_line_style(1, 1)
        chart_url = chart.get_url()
    
    return render_to_response('sentry/group.html', locals())
开发者ID:bryanchow,项目名称:django-sentry,代码行数:64,代码来源:views.py

示例13: render

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_line_style [as 别名]

#.........这里部分代码省略.........
                max_config.__dict__.update(serie_config.__dict__)
                max_config.__dict__.update(serie_config.max)
                str_max_data = str(round(converter.convert(measure, max_data), 1))
                chart.add_marker(index, max_index, 't'+str_max_data, _valid_color(max_config.text), max_config.size)
                chart.add_marker(index, max_index, max_config.style, _valid_color(max_config.color), max_config.thickness)

            if serie_config.min and not min_index == None:
                min_config = ChartConfig()
                min_config.__dict__.update(serie_config.__dict__)
                min_config.__dict__.update(serie_config.min)
                str_min_data = str(round(converter.convert(measure, min_data), 1))
                chart.add_marker(index, min_index, 't'+str_min_data, _valid_color(min_config.text), min_config.size)
                chart.add_marker(index, min_index, min_config.style, _valid_color(min_config.color), min_config.thickness)

            if serie_config.last:
                last_config = ChartConfig()
                last_config.__dict__.update(serie_config.__dict__)
                last_config.__dict__.update(serie_config.last)
                last_index=len(serie_data)-1
                last_data = serie_data[last_index]
                if last_data:
                    str_last_data = str(round(converter.convert(measure, last_data), 1))
                    chart.add_marker(index, last_index, 't'+str(last_data), _valid_color(last_config.text), last_config.size)
                    chart.add_marker(index, last_index, last_config.style, _valid_color(last_config.color), last_config.thickness)

            if serie_config.area:
                fill_config = ChartConfig()
                fill_config.__dict__.update(serie_config.__dict__)
                fill_config.__dict__.update(serie_config.area)
                to = ordered_keys.index(fill_config.to)
                chart.add_fill_range(_valid_color(fill_config.color), index, to)

            if serie_config.dash:
                chart.set_line_style(index, serie_config.thickness, serie_config.dash, serie_config.dash)
            else:
                chart.set_line_style(index, serie_config.thickness)

            if serie_config.legend:
                legend.append(serie_config.legend)
                legend_set = True
            else:
                legend.append('')

            if serie_config.marks:
                mark_config = ChartConfig()
                mark_config.__dict__.update(serie_config.__dict__)
                mark_config.__dict__.update(serie_config.marks)
                mark_data = copy.copy(data[mark_config.serie.split('.')[0]]['series'][mark_config.serie.split('.')[1]])
                mark_data = compress_to(mark_data, config.nval, min_index, max_index)[0]
                for i, m in enumerate(mark_data):
                    if not m:
                        mark_data[i] = " "
                density = max(1.0, 1.0 * mark_config.space * len("".join(mark_data))*mark_config.size  / config.width)

                for i, v in enumerate(mark_data):
                    if (i +1) % round(density) == 0:
                        if serie_data[i] != 0:
                            text = str(mark_data[i])
                        else:
                            text = " "
                        chart.add_marker(index, i, 't'+text, _valid_color(mark_config.color), mark_config.size)

            index = index + 1

        # Compute vertical range
开发者ID:gmassei,项目名称:wfrog,代码行数:69,代码来源:chart.py


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