Beispiel #1
0
def write_pie_chart_data(chart, index):

    selector = ColorSelector()

    script = "var data" + str(index) + " = ["

    for i in range(len(chart.get_all_data_from_set(chart.get_data_sets()[0]))):

        color = selector.get_random_color()

        data_val = chart.get_all_data_from_set(chart.get_data_sets()[0])[i]

        script += '{value:' + str(
            data_val
        ) + ',color:"#' + color + '", highlight: "#' + color + '", label: "' + str(
            chart.get_data_labels()[i]) + '" }'

        if i != (len(chart.get_all_data_from_set(
                chart.get_data_sets()[0]))) - 1:
            script += ','

    script += "];\n"

    script += 'var myPieChart = new Chart(chartref.getContext("2d")).Pie(data' + str(
        index) + ');'

    return script
Beispiel #2
0
def write_pie_chart_data(chart, index):

    selector = ColorSelector()

    script = "var data"+str(index)+" = ["

    for i in range(len(chart.get_all_data_from_set(chart.get_data_sets()[0]))):

        color = selector.get_random_color()

        data_val = chart.get_all_data_from_set(chart.get_data_sets()[0])[i]

        script += '{value:'+str(data_val)+',color:"#'+color+'", highlight: "#'+color+'", label: "'+str(chart.get_data_labels()[i])+'" }'

        if i != (len(chart.get_all_data_from_set(chart.get_data_sets()[0]))) - 1:
            script += ','

    script += "];\n"

    script += 'var myPieChart = new Chart(chartref.getContext("2d")).Pie(data'+str(index)+');'

    return script
Beispiel #3
0
def write_line_chart_data(chart, index):

    """

    :param chart :
    :return:
    """

    # create a selector for getting colors
    selector = ColorSelector()

    # Variable declaration that stores chart info
    script = "var data"+str(index)+" = {\n"

    # get correct labels
    labels = []
    if chart.can_sort_data_numerically():
        labels = chart.get_sorted_labels()
    else:
        labels = chart.get_data_labels()
    script += 'labels:'+str(labels) + ', '

    # Print out the data set info
    script += "datasets : ["

    for s in range(len(chart.get_data_sets())):

        data_set = chart.get_data_sets()[s]

        data = []

        if chart.can_sort_data_numerically():
            data = chart.sort_data_set_by_label(data_set)
        else:
            data = chart.get_all_data_from_set(data_set)

        color = selector.get_random_color()

        script += '{\n'
        script += 'data: ' + str(data) + ',\n'
        script += 'label:"' + data_set + '",\n'
        script += 'fillColor:' + '"rgba(220,220,220,0.0)" ,\n'
        script += 'strokeColor:' + '"#'+color + '",\n'
        script += 'pointColor:' + '"#'+color + '",\n'
        script += 'pointStrokeColor:' + '"#'+color + '",\n'
        script += 'pointHighlightFill:' + '"#'+color + '",\n'
        script += 'pointHighlightStroke:' + "'#"+color + "'\n"
        script += '}'

        if s < len(chart.get_data_sets())-1:
            script += ","

    script += "]};\n"

    if chart.get_chart_type() == "Line":
        script += "var myLineChart = new Chart(chartref.getContext('2d')).Line(data"+str(index)+");\n"

    elif chart.get_chart_type() == "Bar":
        script += "var myBarChart = new Chart(chartref.getContext('2d')).Bar(data"+str(index)+");\n"

    elif chart.get_chart_type() == "Radar":
        script += "var myRadarChart = new Chart(chartref.getContext('2d')).Radar(data"+str(index)+");\n"

    return script
Beispiel #4
0
def write_line_chart_data(chart, index):
    """

    :param chart :
    :return:
    """

    # create a selector for getting colors
    selector = ColorSelector()

    # Variable declaration that stores chart info
    script = "var data" + str(index) + " = {\n"

    # get correct labels
    labels = []
    if chart.can_sort_data_numerically():
        labels = chart.get_sorted_labels()
    else:
        labels = chart.get_data_labels()
    script += 'labels:' + str(labels) + ', '

    # Print out the data set info
    script += "datasets : ["

    for s in range(len(chart.get_data_sets())):

        data_set = chart.get_data_sets()[s]

        data = []

        if chart.can_sort_data_numerically():
            data = chart.sort_data_set_by_label(data_set)
        else:
            data = chart.get_all_data_from_set(data_set)

        color = selector.get_random_color()

        script += '{\n'
        script += 'data: ' + str(data) + ',\n'
        script += 'label:"' + data_set + '",\n'
        script += 'fillColor:' + '"rgba(220,220,220,0.0)" ,\n'
        script += 'strokeColor:' + '"#' + color + '",\n'
        script += 'pointColor:' + '"#' + color + '",\n'
        script += 'pointStrokeColor:' + '"#' + color + '",\n'
        script += 'pointHighlightFill:' + '"#' + color + '",\n'
        script += 'pointHighlightStroke:' + "'#" + color + "'\n"
        script += '}'

        if s < len(chart.get_data_sets()) - 1:
            script += ","

    script += "]};\n"

    if chart.get_chart_type() == "Line":
        script += "var myLineChart = new Chart(chartref.getContext('2d')).Line(data" + str(
            index) + ");\n"

    elif chart.get_chart_type() == "Bar":
        script += "var myBarChart = new Chart(chartref.getContext('2d')).Bar(data" + str(
            index) + ");\n"

    elif chart.get_chart_type() == "Radar":
        script += "var myRadarChart = new Chart(chartref.getContext('2d')).Radar(data" + str(
            index) + ");\n"

    return script