1

I want to serve my csv data to google charts for bubble chart on google, but I have little problem, I cannot create a array

This is my python data

```
    python_data = {
    'some_list': ["USA", "CN", "EU"],
    'some_list_2': [2, 5, 8],
    'some_list_3': [2, 3, 4],
    'some_list_4': [40, 500, 68]}
 ```

I want to serve this data in js like this.


    var data = google.visualization.arrayToDataTable([
            ['ID', 'Life Expectancy', 'Fertility Rate', 'Population'],
            ['CAN',    80.66,              1.67,        33739900],
            ['DEU',    79.84,              1.36,            81902307],
            ['DNK',    78.6,               1.84,            5523095],
            ['EGY',    72.73,              2.78,          79716203],
            ['GBR',    80.05,              2,             61801570],
            ['IRN',    72.49,              1.7,          73137148],
            ['IRQ',    68.09,              4.77,         31090763],
            ['ISR',    81.55,              2.96,        7485600],
            ['RUS',    68.6,               1.54,        141850000],
            ['USA',    78.09,              2.05,      307007000]
          ]);

at the en of the day i want to run this function on my flask website

  <script type="text/javascript">
    google.charts.load("current", {packages:["corechart"]});
    google.charts.setOnLoadCallback(drawChart);

    function drawChart() {

      var data = google.visualization.arrayToDataTable([
        ['ID', 'Life Expectancy', 'Fertility Rate', 'Region',     'Population'],
        ['CAN',    80.66,              1.67,      'North America',  33739900],
        ['DEU',    79.84,              1.36,      'Europe',         81902307],
        ['DNK',    78.6,               1.84,      'Europe',         5523095],
        ['EGY',    72.73,              2.78,      'Middle East',    79716203],
        ['GBR',    80.05,              2,         'Europe',         61801570],
        ['IRN',    72.49,              1.7,       'Middle East',    73137148],
        ['IRQ',    68.09,              4.77,      'Middle East',    31090763],
        ['ISR',    81.55,              2.96,      'Middle East',    7485600],
        ['RUS',    68.6,               1.54,      'Europe',         141850000],
        ['USA',    78.09,              2.05,      'North America',  307007000]
      ]);

      var options = {
        title: 'Correlation between life expectancy, fertility rate ' +
               'and population of some world countries (2010)',
        hAxis: {title: 'Life Expectancy'},
        vAxis: {title: 'Fertility Rate'},
        bubble: {
          textStyle: {
            fontSize: 12,
            fontName: 'Times-Roman',
            color: 'green',
            bold: true,
            italic: true
          }
        }
      };

      var chart = new google.visualization.BubbleChart(document.getElementById('textstyle'));

      chart.draw(data, options);
    }
  </script>

Thank you for your attention and help :)

1 Answer 1

1

You basically have two options:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.