Changing the color of bubbles in a Google visualization motion chart

Am I where I can determine the colors of the bubbles in the motion diagram provided by the Google visualization API? I do not want to use the default color scheme .

Thanks in advance.

+3
source share
2 answers

I did not find a built-in way to do this. However, what you can do is assign each bubble a “colored” variable. Then you can set the color of the bubbles for this variable. I found that for 3 bubbles, from 1 to 1, from another to 1.5 and from third to 3 projects, it’s good enough (by default, yellow projects are very bad in the color scheme). This approach gives you limited control over the color scheme.

+1
source

This is 2017, and I have yet to find a good update for this. So, here is the solution I came up with. NTN.

#views.py
# Bubble Chart: ID, X, Y Color, Size
data.append(['ID', 'X', 'Y', 'Category', 'Z'])
data.append(['', 0, 0, 'Cat 1', 0]) #<-- the order of 
data.append(['', 0, 0, 'Cat 2', 0]) #<-- these fakeout items
data.append(['', 0, 0, 'Cat 3', 0]) #<-- is important
data.append(['', 0, 0, 'Cat 4', 0]) #<-- Blue, Red, Orange, Green - in that order

... for r in the source: data.append (ra, rb, rc, rd, re)

return render(
    request,
    'Template.html',
    {
        'title':'',
        'year':datetime.now().year,
        'org': org,
        'data': json.dumps(data),
    }

#in the scripts block of template.html

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
    google.charts.load('current', {'packages':['corechart']});
    google.charts.setOnLoadCallback(drawChart);

    function drawChart() {

        var data = google.visualization.arrayToDataTable({{data|safe}});

        var options = {
            title: 'Bubble By Category Strategy',
            hAxis: { title: 'X', ticks: [{v: 0, f:''}, {v: 1, f:'L'}, {v: 2, f:'M'}, {v: 3, f:'H'}, {v: 4, f:''}] },
            vAxis: { title: 'Y', ticks: [{v: 0, f:''}, {v: 1, f:'L'}, {v: 2, f:'M'}, {v: 3, f:'H'}, {v: 4, f:''}]  },
            bubble: {
                textStyle: {
                    fontSize: 11,
                    fontName: 'Lato',
                }
            }
        };

        var chart = new google.visualization.BubbleChart(document.getElementById('riskChart'));
        chart.draw(data, options);
    }

</script>
0
source

Source: https://habr.com/ru/post/1760111/


All Articles