简体   繁体   中英

How can I manage Google Charts Data Properties properly?

I am trying to configure the porperties for my DataTable in js for Google Charts. I am already configuring this, and it is working but it broke on me a few times the past month and I had to update my method call.

  var data = google.visualization.arrayToDataTable([]);

The first way I used to do this is with the code below which worked until recently (I tested it it yesterday, but haven't looked at it for a couple weeks before):

// Check if column title includes Projection.
          if(**data.Sf[i]**["label"].indexOf('Projection') > -1 )
          { 
              //Do Action 
          }
          else
          {
                //Do else action
          }

Once the above code broke, I moved on to change the data.Sf to data.pg with no other code changes. This fixed the problem. My concern is that this way of going about things can possibly break again, and I am wondering if there is safer or more consistent way to go about looking at the title for each column in the data table.

there are several helper methods

you shouldn't need to access the objects directly

to get the column label, use...

dataTable.getColumnLabel(colIndex)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM