|
26 | 26 | return year + (month - 1) / 12; |
27 | 27 | } |
28 | 28 |
|
29 | | - const xs = points.map(p => toDecimalYear(p.month)); |
30 | | - const ys = points.map(p => p.count); |
| 29 | + if (points.length === 0) { |
| 30 | + document.getElementById('chart').innerHTML = '<p class="no-data">No data points available.</p>'; |
| 31 | + } else { |
| 32 | + const xs = points.map(p => toDecimalYear(p.month)); |
| 33 | + const ys = points.map(p => p.count); |
31 | 34 |
|
32 | | - const lastPoint = points[points.length - 1]; |
33 | | - const formattedDate = updated ? updated.replace(/-/g, '/') : ''; |
34 | | - const formattedCount = lastPoint.count.toLocaleString(); |
35 | | - const title = `As of ${formattedDate} there were ${formattedCount} Web VPython accounts.`; |
| 35 | + const lastPoint = points[points.length - 1]; |
| 36 | + const formattedDate = updated ? updated.replace(/-/g, '/') : ''; |
| 37 | + const formattedCount = lastPoint.count.toLocaleString(); |
| 38 | + const title = `As of ${formattedDate} there were ${formattedCount} Web VPython accounts.`; |
36 | 39 |
|
37 | | - Plotly.newPlot('chart', [{ |
38 | | - x: xs, |
39 | | - y: ys, |
40 | | - mode: 'lines+markers', |
41 | | - type: 'scatter', |
42 | | - marker: { color: 'red', size: 4 }, |
43 | | - line: { color: 'red', width: 1 } |
44 | | - }], { |
45 | | - title: title, |
46 | | - xaxis: { title: 'Year' }, |
47 | | - yaxis: { title: 'Web VPython accounts' }, |
48 | | - margin: { t: 60 } |
49 | | - }); |
| 40 | + try { |
| 41 | + Plotly.newPlot('chart', [{ |
| 42 | + x: xs, |
| 43 | + y: ys, |
| 44 | + mode: 'lines+markers', |
| 45 | + type: 'scatter', |
| 46 | + marker: { color: 'red', size: 4 }, |
| 47 | + line: { color: 'red', width: 1 } |
| 48 | + }], { |
| 49 | + title: title, |
| 50 | + xaxis: { title: 'Year' }, |
| 51 | + yaxis: { title: 'Web VPython accounts' }, |
| 52 | + margin: { t: 60 } |
| 53 | + }); |
| 54 | + } catch (e) { |
| 55 | + document.getElementById('chart').innerHTML = '<p class="no-data">Chart failed to render: ' + e.message + '</p>'; |
| 56 | + } |
| 57 | + } |
50 | 58 | </script> |
51 | 59 | {% endif %} |
52 | 60 | </body> |
|
0 commit comments