{"id":19599,"date":"2016-09-07T14:19:59","date_gmt":"2016-09-07T14:19:59","guid":{"rendered":"https:\/\/legacy.livecode.com\/?p=19599"},"modified":"2016-09-19T05:55:35","modified_gmt":"2016-09-19T05:55:35","slug":"livecode-widgets-the-line-chart","status":"publish","type":"post","link":"https:\/\/legacy.livecode.com\/livecode-widgets-the-line-chart\/","title":{"rendered":"LiveCode Widgets: The Line Chart"},"content":{"rendered":"<p>There&#8217;s nothing quite like a good chart for presenting data in a way that is easy for people to quickly understand. A few of us around the office even get strangely excited by chart bling so it&#8217;s no surprise that the Line Chart was high on the agenda for LiveCode 8. For someone like me that has spent many hours implementing charts in LiveCode over the years having a chart right there in the tool palette to drag onto my stack is just lovely. <!--more--><\/p>\n<p>There&#8217;s nothing quite like a good chart for presenting data in a way that is easy for people to quickly understand. A few of us around the office even get strangely excited by chart bling so it&#8217;s no surprise that the Line Chart was high on the agenda for LiveCode 8. For someone like me that has spent many hours implementing charts in LiveCode over the years having a chart right there in the tool palette to drag onto my stack is just lovely. Today I will introduce the functionality of the widget (as it is in LiveCode 8.1 RC1) and over the next couple of posts I&#8217;ll be detailing what I needed to do to add some features. There&#8217;s also a few more features worked through at the end of the Widgets One course for those of you taking that.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19600 size-full\" src=\"https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog1.png\" alt=\"blog1\" width=\"300\" height=\"175\" \/><\/p>\n<p>When you first drag the Line Chart out from the tools palette onto your stack you will see it is pre-initialised with a few series of data so you already have something that looks like a chart. All of the properties of the Line Chart are available via the inspector as seen in the image below but I will discuss how to interact with them in code as many of you\u00a0will want to when using\u00a0it in your application.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19765 size-full\" src=\"https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-07-at-9.08.22-AM.png\" alt=\"Screen Shot 2016-09-07 at 9.08.22 AM\" width=\"358\" height=\"467\" srcset=\"https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-07-at-9.08.22-AM.png 358w, https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-07-at-9.08.22-AM-230x300.png 230w\" sizes=\"auto, (max-width: 358px) 100vw, 358px\" \/><\/p>\n<p>Unarguably the most important property you will need to know about as you start using the Line Chart is the graphData. The graphData is comma and line delimited with the first item of each line being a point on the X axis and each subsequent item on a line being a point on the Y axis of a data series.<\/p>\n<p>For example, using maximum temperature averages (\u00b0C) for Edinburgh, Scotland and Geeveston, Tasmania will allow you to easily see why I&#8217;m happy I&#8217;m allowed to work from home:<\/p>\n<pre><code>local tData\r\nput \"Jan,6,22\" &amp; return &amp; \r\n       \"Feb,6,22\" &amp; return &amp; \r\n       \"Mar,8,20\" &amp; return &amp; \r\n       \"Apr,11,17\" &amp; return &amp; \r\n       \"May,14,15\" &amp; return &amp; \r\n       \"Jun,17,12\" &amp; return &amp; \r\n       \"Jul,11,18\" &amp; return &amp; \r\n       \"Aug,18,13\" &amp; return &amp; \r\n       \"Sep,16,15\" &amp; return &amp; \r\n       \"Oct,12,16\" &amp; return &amp; \r\n       \"Nov,9,18\" &amp; return &amp; \r\n       \"Dec,7,20\" into tData\r\nset the graphData of widget \"Line Graph\" to tData\r\n<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19604 size-full\" src=\"https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog2.png\" alt=\"blog2\" width=\"361\" height=\"250\" srcset=\"https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog2.png 361w, https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog2-300x208.png 300w\" sizes=\"auto, (max-width: 361px) 100vw, 361px\" \/><\/p>\n<p>Actually Kevin I&#8217;m available to come over any time between mid-May and the end of August \ud83d\ude09<\/p>\n<p>At the moment our chart looks a little busy so it would be nice to clean it up a bit with the following:<\/p>\n<pre><code>set the graphXLines of widget \"Line Graph\" to false\r\nset the graphYLines of widget \"Line Graph\" to false\r\nset the markerStyles of widget \"Line Graph\" to empty\r\n<\/code><\/pre>\n<p>What we are doing here is removing the grid behind the chart and removing the markers from the lines as seen in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19606 size-full\" src=\"https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog3.png\" alt=\"blog3\" width=\"361\" height=\"250\" srcset=\"https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog3.png 361w, https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog3-300x208.png 300w\" sizes=\"auto, (max-width: 361px) 100vw, 361px\" \/><\/p>\n<p>While we are discussing the markerStyles property I&#8217;ll just point out that the next post in this series will cover what I needed to do to implement the markerStyles and the showLines properties. These properties are both new in LiveCode 8.1. For now I&#8217;ll just explain what you can use these properties for. A marker style may be empty, circle, diamond, square, filled circle, filled diamond or filled square. The showLines governs the line visibility so that you can just show markers:<\/p>\n<pre><code>local tMarkers\r\nput \"filled circle\" &amp; return &amp; \"filled diamond\" into tMarkers\r\nset the markerStyles of widget \"Line Graph\" to tMarkers\r\nset the showLines of widget \"Line Graph\" to false\r\n<\/code><\/pre>\n<p>Now we end up with a chart like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19607 size-full\" src=\"https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog4.png\" alt=\"blog4\" width=\"361\" height=\"250\" srcset=\"https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog4.png 361w, https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog4-300x208.png 300w\" sizes=\"auto, (max-width: 361px) 100vw, 361px\" \/><\/p>\n<p>It doesn&#8217;t work very well for this data but it&#8217;s certainly helpful for some use cases if you want a scatterplot type chart.<\/p>\n<p>We can set the line\/marker colors with the graphColors property. For example:<\/p>\n<pre><code>local tNotVeryPretty\r\nput \"255,0,0\" &amp; return &amp; \"0,255,0\" into tNotVeryPretty\r\nset the graphColors of widget \"Line Graph\" to tNotVeryPretty\r\n<\/code><\/pre>\n<p>I won&#8217;t add the image because it&#8217;s not pretty \ud83d\ude09<\/p>\n<p>The other cool feature that the Line Chart currently has is a hilitedCoordinates property. You can set the hilitedCoordinates to a point on any of the lines on the chart. For example:<\/p>\n<pre><code>local tWhenToGoToEdinburgh\r\nput \"Jul,18\" into tWhenToGoToEdinburgh\r\nset the hilitedCoordinates of widget \"Line Graph\" to tWhenToGoToEdinburgh\r\n<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19608 size-full\" src=\"https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog6.png\" alt=\"blog6\" width=\"361\" height=\"250\" srcset=\"https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog6.png 361w, https:\/\/legacy.livecode.com\/wp-content\/uploads\/2016\/09\/blog6-300x208.png 300w\" sizes=\"auto, (max-width: 361px) 100vw, 361px\" \/><\/p>\n<p>I&#8217;d love to hear how you plan to use the Line Chart so let me know in your comments!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&#8217;s nothing quite like a good chart for presenting data in a way that is easy for people to quickly understand. A few of us around the office even get strangely excited by chart bling so it&#8217;s no surprise that the Line Chart was high on the agenda for LiveCode 8. For someone like me<\/p>\n","protected":false},"author":66,"featured_media":19771,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"om_disable_all_campaigns":false,"footnotes":""},"categories":[45],"tags":[192,107],"class_list":["post-19599","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-livecode-8","tag-widgets"],"acf":[],"_links":{"self":[{"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/posts\/19599","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/users\/66"}],"replies":[{"embeddable":true,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/comments?post=19599"}],"version-history":[{"count":19,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/posts\/19599\/revisions"}],"predecessor-version":[{"id":19936,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/posts\/19599\/revisions\/19936"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/media\/19771"}],"wp:attachment":[{"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/media?parent=19599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/categories?post=19599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/tags?post=19599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}