{"id":1843,"date":"2009-03-31T08:59:04","date_gmt":"2009-03-31T13:59:04","guid":{"rendered":"http:\/\/bobbeaty.com\/wp\/?p=1843"},"modified":"2009-03-31T10:42:08","modified_gmt":"2009-03-31T15:42:08","slug":"interesting-gotchas-with-google-visualization-annotatedtimeline","status":"publish","type":"post","link":"https:\/\/bobbeaty.com\/wp\/archives\/1843","title":{"rendered":"Interesting Gotchas with Google Visualization AnnotatedTimeLine"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bobbeaty.com\/wp\/wp-content\/uploads\/2009\/03\/googlevisualization.jpg\" alt=\"GoogleVisualization.jpg\" border=\"0\" width=\"140\" height=\"103\" align=\"right\" \/><\/p>\n<p>I have been messing with the <a href=\"http:\/\/code.google.com\/apis\/visualization\/\">Google Visualization's<\/a> <a href=\"http:\/\/code.google.com\/apis\/visualization\/documentation\/gallery\/annotatedtimeline.html\">AnnotatedTimeLine<\/a> widget on my webapp, and while it's <em>wonderful<\/em> in so many ways, there are a few 'gotchas' that I've run into - and I'm not alone on one of these.<\/p>\n<h3>Specifying Column Index in Hiding\/Showing Columns<\/h3>\n<p>The <a href=\"http:\/\/code.google.com\/apis\/visualization\/documentation\/gallery\/annotatedtimeline.html\">AnnotatedTimeLine<\/a> has some really nice methods that allow you to show\/hide the lines on the graph (columns in the <a href=\"http:\/\/code.google.com\/apis\/visualization\/documentation\/reference.html#DataTable\">DataTable<\/a>):<\/p>\n<pre class=\"javascript\" style=\"font-family:monospace;\">    chart.<span style=\"color: #660066;\">hideDataColumns<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #CC0000;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n    chart.<span style=\"color: #660066;\">showDataColumns<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #CC0000;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><\/pre>\n<p>the problem is that the <tt>columnIndex<\/tt> that you'd <em>think<\/em> you needed to pass in would probably be <strong>wrong<\/strong>. They are looking for the <strong><em>dataset index<\/em><\/strong> and for that, you have to remember that the date data in column 0 of the table is really <strong>not<\/strong> considered in this calculation.<\/p>\n<p>So, if you have the name of the column and want to make it disappear, you need to have a function like:<\/p>\n<pre class=\"javascript\" style=\"font-family:monospace;\">    <span style=\"color: #000066; font-weight: bold;\">function<\/span> toggleView<span style=\"color: #009900;\">&#40;<\/span>name<span style=\"color: #339933;\">,<\/span> state<span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n      <span style=\"color: #000066; font-weight: bold;\">var<\/span> i<span style=\"color: #339933;\">;<\/span>\n      <span style=\"color: #000066; font-weight: bold;\">var<\/span> colCnt <span style=\"color: #339933;\">=<\/span> graphData.<span style=\"color: #660066;\">getNumberOfColumns<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      <span style=\"color: #000066; font-weight: bold;\">for<\/span> <span style=\"color: #009900;\">&#40;<\/span>i <span style=\"color: #339933;\">=<\/span> <span style=\"color: #CC0000;\">1<\/span><span style=\"color: #339933;\">;<\/span> i <span style=\"color: #339933;\">&lt;<\/span> colCnt<span style=\"color: #339933;\">;<\/span> i<span style=\"color: #339933;\">++<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n        <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">&#40;<\/span>graphData.<span style=\"color: #660066;\">getColumnLabel<\/span><span style=\"color: #009900;\">&#40;<\/span>i<span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #339933;\">==<\/span> name<span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n          <span style=\"color: #006600; font-style: italic;\">\/\/ the dataset number is one less than the column number<\/span>\n          <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">&#40;<\/span>state<span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n            chart.<span style=\"color: #660066;\">showDataColumns<\/span><span style=\"color: #009900;\">&#40;<\/span>i<span style=\"color: #339933;\">-<\/span><span style=\"color: #CC0000;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n          <span style=\"color: #009900;\">&#125;<\/span> <span style=\"color: #000066; font-weight: bold;\">else<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n            chart.<span style=\"color: #660066;\">hideDataColumns<\/span><span style=\"color: #009900;\">&#40;<\/span>i<span style=\"color: #339933;\">-<\/span><span style=\"color: #CC0000;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n          <span style=\"color: #009900;\">&#125;<\/span>\n        <span style=\"color: #009900;\">&#125;<\/span>\n      <span style=\"color: #009900;\">&#125;<\/span>\n    <span style=\"color: #009900;\">&#125;<\/span><\/pre>\n<p>If you remember to have the right offset, it all works fine.<\/p>\n<h3>Showing a Hidden Line Bug<\/h3>\n<p>I found a reference to this on the <a href=\"http:\/\/code.google.com\/apis\/visualization\/\">Google Visualization<\/a> mailing list. It turns out that if you try to show a hidden line, it doesn't work. But if you cycle it <em>twice<\/em> then it works. Meaning this <strong>doesn't<\/strong> work:<\/p>\n<pre class=\"javascript\" style=\"font-family:monospace;\">    <span style=\"color: #006600; font-style: italic;\">\/\/ hide the line on the graph<\/span>\n    chart.<span style=\"color: #660066;\">hideDataColumns<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #CC0000;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n    <span style=\"color: #006600; font-style: italic;\">\/\/ show the line we just hid<\/span>\n    chart.<span style=\"color: #660066;\">showDataColumns<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #CC0000;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><\/pre>\n<p>but this <strong><em>does<\/em><\/strong>:<\/p>\n<pre class=\"javascript\" style=\"font-family:monospace;\">    <span style=\"color: #006600; font-style: italic;\">\/\/ hide the line on the graph<\/span>\n    chart.<span style=\"color: #660066;\">hideDataColumns<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #CC0000;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n    <span style=\"color: #006600; font-style: italic;\">\/\/ show the line we just hid<\/span>\n    chart.<span style=\"color: #660066;\">showDataColumns<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #CC0000;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n    chart.<span style=\"color: #660066;\">hideDataColumns<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #CC0000;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n    chart.<span style=\"color: #660066;\">showDataColumns<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #CC0000;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><\/pre>\n<p>It's the \"second cycle\" on the 'show' side of things that makes the difference. This is an acknowledged bug by Google, and the good news is that as soon as they fix it, we're going to get the fix. Nice.<\/p>\n<p><strong>UPDATE:<\/strong> With the 3\/30\/2009 Release Candidate from Google, this is <strong><em>fixed!<\/em><\/strong> Yup, just use the version \"1.1\" in the <tt>google.load()<\/tt> javascript call and you'll set it. It's set to go to production on 4\/6, and at that point, version \"1\" will again get it. Excellent update!<\/p>\n<p>So... just keep these in mind if you're using this widget.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been messing with the Google Visualization&#8217;s AnnotatedTimeLine widget on my webapp, and while it&#8217;s wonderful in so many ways, there are a few &#8216;gotchas&#8217; that I&#8217;ve run into &#8211; and I&#8217;m not alone on one of these. Specifying Column Index in Hiding\/Showing Columns The AnnotatedTimeLine has some really nice methods that allow you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-1843","post","type-post","status-publish","format-standard","hentry","category-coding","category-open-source-software"],"_links":{"self":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/1843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/comments?post=1843"}],"version-history":[{"count":3,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/1843\/revisions"}],"predecessor-version":[{"id":1846,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/1843\/revisions\/1846"}],"wp:attachment":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/media?parent=1843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/categories?post=1843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/tags?post=1843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}