| 77 | |
| 78 | === History graph colouring === |
| 79 | |
| 80 | If you pay different tariffs depending on time of use, you can define a snippet of code which assigns a colour to each bar in the history graphs of child devices. |
| 81 | |
| 82 | For the two-hourly graph, create a variable with service ID '''urn:futzle-com:serviceId:CurrentCostEnviR1''' and variable name '''TwoHourlyHistoryColour'''. For the daily graph, create a variable with the same service ID and variable name '''DailyHistoryColour'''. For the monthly graph, create a variable with the same service ID and variable name '''MonthlyHistoryColour'''. (Americans take note at the spelling of these variables.) |
| 83 | |
| 84 | The contents of the variable is a JavaScript fragment which evaluates to a string in the form '''RRGGBB'''. A variable '''time''' contains a JavaScript '''Date''' object corresponding to the start time of that bar in the graph. |
| 85 | |
| 86 | Examples: |
| 87 | * In the two-hourly graph, to display red from 7 am to 11 pm on weekdays, and blue at other times: |
| 88 | `time.getHours() >= 23 || !(time.getHours() >= 7) || time.getDay() == 0 || time.getDay() == 6 ? '4D89F9' : 'CC5544'` |
| 89 | * In the daily graph, to display purple for weekdays, and blue on weekends: |
| 90 | `time.getDay() == 0 || time.getDay() == 6 ? '4D89F9' : 'AA55CC'` |
| 91 | |
| 92 | Note how the logic has been written to avoid HTML-special characters '''&''' and '''<'''. |