Rendering Google charts based on a generated array












1















The problem:



I am trying to present this:enter image description here



As a Google Chart. This is my array:



[
[
"3600000",
21,
9,
12
],
[
"18000000",
33,
5,
28
],
[
"86400000",
211,
14,
197
],
[
"172800000",
230,
7,
223
],
[
"259200000",
145,
1,
144
],
[
"345600000",
150,
2,
148
],
[
"432000000",
266,
5,
261
],
[
"518400000",
350,
2,
348
],
[
"604800000",
398,
3,
395
],
[
"1209600000",
2544,
19,
2525
],
[
"2592000000",
3758,
45,
3713
],
[
"5184000000",
5306,
28,
5278
]
]


So what I tried to do was this:



<Chart
chartType="Line"
loader={<div>Loading Chart</div>}
data={[
[
'Czas',
'Wszyscy',
'Rozwiazujacy',
'Uczniowie',
// 'Admini',
],
this.state.sortedForChart.map(ch => {
console.log(ch);
// This logs arrays like this:
// ["259200000", 144, 1, 143]

return ch;
})
// These are the examples provided by Google.
// [1, 37.8, 80.8, 41.8],
// [2, 30.9, 69.5, 32.4],
// [3, 25.4, 57, 25.7],
// [4, 11.7, 18.8, 10.5],
// [5, 11.9, 17.6, 10.4],
// [6, 8.8, 13.6, 7.7],
// [7, 7.6, 12.3, 9.6],
// [8, 12.3, 29.2, 10.6],
// [9, 16.9, 42.9, 14.8],
// [10, 12.8, 30.9, 11.6],
// [11, 5.3, 7.9, 4.7],
// [12, 6.6, 8.4, 5.2],
// [13, 4.8, 6.3, 3.6],
// [14, 4.2, 6.2, 3.4],
]}
options={{
chart: {
title: 'Czestotliwosc logowania',
},
}}
/>


But this failed. The error says:




Error: Row 0 has 13 columns, but must have 4 jsapi_compiled_default_module.js:129:153




So I'm assuming it's not actually returning the value, because if I do this:



data={[
[
'Czas',
'Wszyscy',
'Rozwiazujacy',
'Uczniowie',
],
[
"3600000",
20,
9,
11
],
[
"5184000000",
5306,
28,
5278
]
]}


This produces a nice and accurate chart. But I cannot think of a way to make it work so that I don't have to type in each part of the array. Any ideas?



Edit: This works as well:



data={[
[
'Czas',
'Wszyscy',
'Rozwiazujacy',
'Uczniowie',
// 'Admini',
],
// return this.state.sortedForChart.map(ch => ch);
this.state.sortedForChart[0],
this.state.sortedForChart[1],
]}









share|improve this question





























    1















    The problem:



    I am trying to present this:enter image description here



    As a Google Chart. This is my array:



    [
    [
    "3600000",
    21,
    9,
    12
    ],
    [
    "18000000",
    33,
    5,
    28
    ],
    [
    "86400000",
    211,
    14,
    197
    ],
    [
    "172800000",
    230,
    7,
    223
    ],
    [
    "259200000",
    145,
    1,
    144
    ],
    [
    "345600000",
    150,
    2,
    148
    ],
    [
    "432000000",
    266,
    5,
    261
    ],
    [
    "518400000",
    350,
    2,
    348
    ],
    [
    "604800000",
    398,
    3,
    395
    ],
    [
    "1209600000",
    2544,
    19,
    2525
    ],
    [
    "2592000000",
    3758,
    45,
    3713
    ],
    [
    "5184000000",
    5306,
    28,
    5278
    ]
    ]


    So what I tried to do was this:



    <Chart
    chartType="Line"
    loader={<div>Loading Chart</div>}
    data={[
    [
    'Czas',
    'Wszyscy',
    'Rozwiazujacy',
    'Uczniowie',
    // 'Admini',
    ],
    this.state.sortedForChart.map(ch => {
    console.log(ch);
    // This logs arrays like this:
    // ["259200000", 144, 1, 143]

    return ch;
    })
    // These are the examples provided by Google.
    // [1, 37.8, 80.8, 41.8],
    // [2, 30.9, 69.5, 32.4],
    // [3, 25.4, 57, 25.7],
    // [4, 11.7, 18.8, 10.5],
    // [5, 11.9, 17.6, 10.4],
    // [6, 8.8, 13.6, 7.7],
    // [7, 7.6, 12.3, 9.6],
    // [8, 12.3, 29.2, 10.6],
    // [9, 16.9, 42.9, 14.8],
    // [10, 12.8, 30.9, 11.6],
    // [11, 5.3, 7.9, 4.7],
    // [12, 6.6, 8.4, 5.2],
    // [13, 4.8, 6.3, 3.6],
    // [14, 4.2, 6.2, 3.4],
    ]}
    options={{
    chart: {
    title: 'Czestotliwosc logowania',
    },
    }}
    />


    But this failed. The error says:




    Error: Row 0 has 13 columns, but must have 4 jsapi_compiled_default_module.js:129:153




    So I'm assuming it's not actually returning the value, because if I do this:



    data={[
    [
    'Czas',
    'Wszyscy',
    'Rozwiazujacy',
    'Uczniowie',
    ],
    [
    "3600000",
    20,
    9,
    11
    ],
    [
    "5184000000",
    5306,
    28,
    5278
    ]
    ]}


    This produces a nice and accurate chart. But I cannot think of a way to make it work so that I don't have to type in each part of the array. Any ideas?



    Edit: This works as well:



    data={[
    [
    'Czas',
    'Wszyscy',
    'Rozwiazujacy',
    'Uczniowie',
    // 'Admini',
    ],
    // return this.state.sortedForChart.map(ch => ch);
    this.state.sortedForChart[0],
    this.state.sortedForChart[1],
    ]}









    share|improve this question



























      1












      1








      1








      The problem:



      I am trying to present this:enter image description here



      As a Google Chart. This is my array:



      [
      [
      "3600000",
      21,
      9,
      12
      ],
      [
      "18000000",
      33,
      5,
      28
      ],
      [
      "86400000",
      211,
      14,
      197
      ],
      [
      "172800000",
      230,
      7,
      223
      ],
      [
      "259200000",
      145,
      1,
      144
      ],
      [
      "345600000",
      150,
      2,
      148
      ],
      [
      "432000000",
      266,
      5,
      261
      ],
      [
      "518400000",
      350,
      2,
      348
      ],
      [
      "604800000",
      398,
      3,
      395
      ],
      [
      "1209600000",
      2544,
      19,
      2525
      ],
      [
      "2592000000",
      3758,
      45,
      3713
      ],
      [
      "5184000000",
      5306,
      28,
      5278
      ]
      ]


      So what I tried to do was this:



      <Chart
      chartType="Line"
      loader={<div>Loading Chart</div>}
      data={[
      [
      'Czas',
      'Wszyscy',
      'Rozwiazujacy',
      'Uczniowie',
      // 'Admini',
      ],
      this.state.sortedForChart.map(ch => {
      console.log(ch);
      // This logs arrays like this:
      // ["259200000", 144, 1, 143]

      return ch;
      })
      // These are the examples provided by Google.
      // [1, 37.8, 80.8, 41.8],
      // [2, 30.9, 69.5, 32.4],
      // [3, 25.4, 57, 25.7],
      // [4, 11.7, 18.8, 10.5],
      // [5, 11.9, 17.6, 10.4],
      // [6, 8.8, 13.6, 7.7],
      // [7, 7.6, 12.3, 9.6],
      // [8, 12.3, 29.2, 10.6],
      // [9, 16.9, 42.9, 14.8],
      // [10, 12.8, 30.9, 11.6],
      // [11, 5.3, 7.9, 4.7],
      // [12, 6.6, 8.4, 5.2],
      // [13, 4.8, 6.3, 3.6],
      // [14, 4.2, 6.2, 3.4],
      ]}
      options={{
      chart: {
      title: 'Czestotliwosc logowania',
      },
      }}
      />


      But this failed. The error says:




      Error: Row 0 has 13 columns, but must have 4 jsapi_compiled_default_module.js:129:153




      So I'm assuming it's not actually returning the value, because if I do this:



      data={[
      [
      'Czas',
      'Wszyscy',
      'Rozwiazujacy',
      'Uczniowie',
      ],
      [
      "3600000",
      20,
      9,
      11
      ],
      [
      "5184000000",
      5306,
      28,
      5278
      ]
      ]}


      This produces a nice and accurate chart. But I cannot think of a way to make it work so that I don't have to type in each part of the array. Any ideas?



      Edit: This works as well:



      data={[
      [
      'Czas',
      'Wszyscy',
      'Rozwiazujacy',
      'Uczniowie',
      // 'Admini',
      ],
      // return this.state.sortedForChart.map(ch => ch);
      this.state.sortedForChart[0],
      this.state.sortedForChart[1],
      ]}









      share|improve this question
















      The problem:



      I am trying to present this:enter image description here



      As a Google Chart. This is my array:



      [
      [
      "3600000",
      21,
      9,
      12
      ],
      [
      "18000000",
      33,
      5,
      28
      ],
      [
      "86400000",
      211,
      14,
      197
      ],
      [
      "172800000",
      230,
      7,
      223
      ],
      [
      "259200000",
      145,
      1,
      144
      ],
      [
      "345600000",
      150,
      2,
      148
      ],
      [
      "432000000",
      266,
      5,
      261
      ],
      [
      "518400000",
      350,
      2,
      348
      ],
      [
      "604800000",
      398,
      3,
      395
      ],
      [
      "1209600000",
      2544,
      19,
      2525
      ],
      [
      "2592000000",
      3758,
      45,
      3713
      ],
      [
      "5184000000",
      5306,
      28,
      5278
      ]
      ]


      So what I tried to do was this:



      <Chart
      chartType="Line"
      loader={<div>Loading Chart</div>}
      data={[
      [
      'Czas',
      'Wszyscy',
      'Rozwiazujacy',
      'Uczniowie',
      // 'Admini',
      ],
      this.state.sortedForChart.map(ch => {
      console.log(ch);
      // This logs arrays like this:
      // ["259200000", 144, 1, 143]

      return ch;
      })
      // These are the examples provided by Google.
      // [1, 37.8, 80.8, 41.8],
      // [2, 30.9, 69.5, 32.4],
      // [3, 25.4, 57, 25.7],
      // [4, 11.7, 18.8, 10.5],
      // [5, 11.9, 17.6, 10.4],
      // [6, 8.8, 13.6, 7.7],
      // [7, 7.6, 12.3, 9.6],
      // [8, 12.3, 29.2, 10.6],
      // [9, 16.9, 42.9, 14.8],
      // [10, 12.8, 30.9, 11.6],
      // [11, 5.3, 7.9, 4.7],
      // [12, 6.6, 8.4, 5.2],
      // [13, 4.8, 6.3, 3.6],
      // [14, 4.2, 6.2, 3.4],
      ]}
      options={{
      chart: {
      title: 'Czestotliwosc logowania',
      },
      }}
      />


      But this failed. The error says:




      Error: Row 0 has 13 columns, but must have 4 jsapi_compiled_default_module.js:129:153




      So I'm assuming it's not actually returning the value, because if I do this:



      data={[
      [
      'Czas',
      'Wszyscy',
      'Rozwiazujacy',
      'Uczniowie',
      ],
      [
      "3600000",
      20,
      9,
      11
      ],
      [
      "5184000000",
      5306,
      28,
      5278
      ]
      ]}


      This produces a nice and accurate chart. But I cannot think of a way to make it work so that I don't have to type in each part of the array. Any ideas?



      Edit: This works as well:



      data={[
      [
      'Czas',
      'Wszyscy',
      'Rozwiazujacy',
      'Uczniowie',
      // 'Admini',
      ],
      // return this.state.sortedForChart.map(ch => ch);
      this.state.sortedForChart[0],
      this.state.sortedForChart[1],
      ]}






      javascript arrays google-visualization






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 '18 at 11:07







      Alex Ironside

















      asked Nov 27 '18 at 10:20









      Alex IronsideAlex Ironside

      1,068725




      1,068725
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Ok solved it!



          let dataForGeneralChart = [[
          'Czas',
          'Wszyscy',
          'Rozwiazujacy',
          'Uczniowie',
          // 'Admini',
          ]];

          sortedForGeneralChart.forEach(ch => {
          dataForGeneralChart.push(ch);
          });


          <Chart
          chartType="Line"
          loader={<div>Loading Chart</div>}
          data={this.state.dataForGeneralChart}
          options={{
          chart: {
          title: 'Czestotliwosc logowania wszystkich',
          },
          }}
          />





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53497453%2frendering-google-charts-based-on-a-generated-array%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Ok solved it!



            let dataForGeneralChart = [[
            'Czas',
            'Wszyscy',
            'Rozwiazujacy',
            'Uczniowie',
            // 'Admini',
            ]];

            sortedForGeneralChart.forEach(ch => {
            dataForGeneralChart.push(ch);
            });


            <Chart
            chartType="Line"
            loader={<div>Loading Chart</div>}
            data={this.state.dataForGeneralChart}
            options={{
            chart: {
            title: 'Czestotliwosc logowania wszystkich',
            },
            }}
            />





            share|improve this answer




























              0














              Ok solved it!



              let dataForGeneralChart = [[
              'Czas',
              'Wszyscy',
              'Rozwiazujacy',
              'Uczniowie',
              // 'Admini',
              ]];

              sortedForGeneralChart.forEach(ch => {
              dataForGeneralChart.push(ch);
              });


              <Chart
              chartType="Line"
              loader={<div>Loading Chart</div>}
              data={this.state.dataForGeneralChart}
              options={{
              chart: {
              title: 'Czestotliwosc logowania wszystkich',
              },
              }}
              />





              share|improve this answer


























                0












                0








                0







                Ok solved it!



                let dataForGeneralChart = [[
                'Czas',
                'Wszyscy',
                'Rozwiazujacy',
                'Uczniowie',
                // 'Admini',
                ]];

                sortedForGeneralChart.forEach(ch => {
                dataForGeneralChart.push(ch);
                });


                <Chart
                chartType="Line"
                loader={<div>Loading Chart</div>}
                data={this.state.dataForGeneralChart}
                options={{
                chart: {
                title: 'Czestotliwosc logowania wszystkich',
                },
                }}
                />





                share|improve this answer













                Ok solved it!



                let dataForGeneralChart = [[
                'Czas',
                'Wszyscy',
                'Rozwiazujacy',
                'Uczniowie',
                // 'Admini',
                ]];

                sortedForGeneralChart.forEach(ch => {
                dataForGeneralChart.push(ch);
                });


                <Chart
                chartType="Line"
                loader={<div>Loading Chart</div>}
                data={this.state.dataForGeneralChart}
                options={{
                chart: {
                title: 'Czestotliwosc logowania wszystkich',
                },
                }}
                />






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 27 '18 at 11:28









                Alex IronsideAlex Ironside

                1,068725




                1,068725
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53497453%2frendering-google-charts-based-on-a-generated-array%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)