Added more updates
[soho-sigint.git] / client-freqwatch / Chart.js / docs / 03-Radar-Chart.md
1 ---
2 title: Radar Chart
3 anchor: radar-chart
4 ---
5
6 ###Introduction
7 A radar chart is a way of showing multiple data points and the variation between them.
8
9 They are often useful for comparing the points of two or more different data sets.
10
11 <div class="canvas-holder">
12         <canvas width="250" height="125"></canvas>
13 </div>
14
15 ###Example usage
16
17 ```javascript
18 var myRadarChart = new Chart(ctx).Radar(data, options);
19 ```
20
21 ###Data structure
22 ```javascript
23 var data = {
24         labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
25         datasets: [
26                 {
27                         label: "My First dataset",
28                         fillColor: "rgba(220,220,220,0.2)",
29                         strokeColor: "rgba(220,220,220,1)",
30                         pointColor: "rgba(220,220,220,1)",
31                         pointStrokeColor: "#fff",
32                         pointHighlightFill: "#fff",
33                         pointHighlightStroke: "rgba(220,220,220,1)",
34                         data: [65, 59, 90, 81, 56, 55, 40]
35                 },
36                 {
37                         label: "My Second dataset",
38                         fillColor: "rgba(151,187,205,0.2)",
39                         strokeColor: "rgba(151,187,205,1)",
40                         pointColor: "rgba(151,187,205,1)",
41                         pointStrokeColor: "#fff",
42                         pointHighlightFill: "#fff",
43                         pointHighlightStroke: "rgba(151,187,205,1)",
44                         data: [28, 48, 40, 19, 96, 27, 100]
45                 }
46         ]
47 };
48 ```
49 For a radar chart, to provide context of what each point means, we include an array of strings that show around each point in the chart.
50 For the radar chart data, we have an array of datasets. Each of these is an object, with a fill colour, a stroke colour, a colour for the fill of each point, and a colour for the stroke of each point. We also have an array of data values.
51
52 The label key on each dataset is optional, and can be used when generating a scale for the chart.
53
54 ### Chart options
55
56 These are the customisation options specific to Radar charts. These options are merged with the [global chart configuration options](#getting-started-global-chart-configuration), and form the options of the chart.
57
58
59 ```javascript
60 {
61         //Boolean - Whether to show lines for each scale point
62         scaleShowLine : true,
63
64         //Boolean - Whether we show the angle lines out of the radar
65         angleShowLineOut : true,
66
67         //Boolean - Whether to show labels on the scale
68         scaleShowLabels : false,
69
70         // Boolean - Whether the scale should begin at zero
71         scaleBeginAtZero : true,
72
73         //String - Colour of the angle line
74         angleLineColor : "rgba(0,0,0,.1)",
75
76         //Number - Pixel width of the angle line
77         angleLineWidth : 1,
78
79         //String - Point label font declaration
80         pointLabelFontFamily : "'Arial'",
81
82         //String - Point label font weight
83         pointLabelFontStyle : "normal",
84
85         //Number - Point label font size in pixels
86         pointLabelFontSize : 10,
87
88         //String - Point label font colour
89         pointLabelFontColor : "#666",
90
91         //Boolean - Whether to show a dot for each point
92         pointDot : true,
93
94         //Number - Radius of each point dot in pixels
95         pointDotRadius : 3,
96
97         //Number - Pixel width of point dot stroke
98         pointDotStrokeWidth : 1,
99
100         //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
101         pointHitDetectionRadius : 20,
102
103         //Boolean - Whether to show a stroke for datasets
104         datasetStroke : true,
105
106         //Number - Pixel width of dataset stroke
107         datasetStrokeWidth : 2,
108
109         //Boolean - Whether to fill the dataset with a colour
110         datasetFill : true,
111         {% raw %}
112         //String - A legend template
113         legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
114         {% endraw %}
115 }
116 ```
117
118
119 You can override these for your `Chart` instance by passing a second argument into the `Radar` method as an object with the keys you want to override.
120
121 For example, we could have a radar chart without a point for each on piece of data by doing the following:
122
123 ```javascript
124 new Chart(ctx).Radar(data, {
125         pointDot: false
126 });
127 // This will create a chart with all of the default options, merged from the global config,
128 //  and the Bar chart defaults but this particular instance will have `pointDot` set to false.
129 ```
130
131 We can also change these defaults values for each Radar type that is created, this object is available at `Chart.defaults.Radar`.
132
133
134 ### Prototype methods
135
136 #### .getPointsAtEvent( event )
137
138 Calling `getPointsAtEvent(event)` on your Chart instance passing an argument of an event, or jQuery event, will return the point elements that are at that the same position of that event.
139
140 ```javascript
141 canvas.onclick = function(evt){
142         var activePoints = myRadarChart.getPointsAtEvent(evt);
143         // => activePoints is an array of points on the canvas that are at the same position as the click event.
144 };
145 ```
146
147 This functionality may be useful for implementing DOM based tooltips, or triggering custom behaviour in your application.
148
149 #### .update( )
150
151 Calling `update()` on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
152
153 ```javascript
154 myRadarChart.datasets[0].points[2].value = 50;
155 // Would update the first dataset's value of 'Sleeping' to be 50
156 myRadarChart.update();
157 // Calling update now animates the position of Sleeping from 90 to 50.
158 ```
159
160 #### .addData( valuesArray, label )
161
162 Calling `addData(valuesArray, label)` on your Chart instance passing an array of values for each dataset, along with a label for those points.
163
164 ```javascript
165 // The values array passed into addData should be one for each dataset in the chart
166 myRadarChart.addData([40, 60], "Dancing");
167 // The new data will now animate at the end of the chart.
168 ```
169
170 #### .removeData( )
171
172 Calling `removeData()` on your Chart instance will remove the first value for all datasets on the chart.
173
174 ```javascript
175 myRadarChart.removeData();
176 // Other points will now animate to their correct positions.
177 ```