]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Label polar area and doughnut datasets
authorEvert Timberg <evert.timberg@gmail.com>
Sat, 5 Dec 2015 01:32:18 +0000 (20:32 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Sat, 5 Dec 2015 01:32:18 +0000 (20:32 -0500)
samples/doughnut.html
samples/polar-area.html
src/core/core.legend.js

index fa78edd8b2cca99a483f2833dbbcc30d6c0f9448..0a6be617ada3606f450126efe0cbe1cfe0e602e0 100644 (file)
@@ -60,6 +60,7 @@
                     "#949FB1",
                     "#4D5360",
                 ],
+                label: 'Dataset 1'
             }, {
                 hidden: true,
                 data: [
@@ -76,6 +77,7 @@
                     "#949FB1",
                     "#4D5360",
                 ],
+                label: 'Dataset 2'
             }, {
                 data: [
                     randomScalingFactor(),
@@ -91,6 +93,7 @@
                     "#949FB1",
                     "#4D5360",
                 ],
+                label: 'Dataset 3'
             }],
             labels: [
                 "Red",
                 position: 'top',
                 title: {
                     display: true,
-                    text: 'Our Favorite Datasets'
+                    text: 'Our Favorite Datasets'
                 }
             },
         }
         var newDataset = {
             backgroundColor: [],
             data: [],
+            label: 'New dataset ' + config.data.datasets.length,
         };
 
         for (var index = 0; index < config.data.labels.length; ++index) {
index 87de0ac09084fd3b491a18b93708bd94a4c75ec0..58f9d57f10f156fe728affa4cebf91e53e99afc1 100644 (file)
@@ -48,6 +48,7 @@
                     "#949FB1",
                     "#4D5360",
                 ],
+                label: 'My dataset' // for legend
             }],
             labels: [
                 "Red",
index f4d6fab4d8090362d45088502dbb8320d778ab9f..fb3776d271fbce226315b44a9eff9efb8631f915 100644 (file)
 
                beforeBuildLabels: helpers.noop,
                buildLabels: function() {
-                       // Convert ticks to strings
                        this.labels = this.chart.data.datasets.map(function(dataset) {
                                return this.options.labels.callback.call(this, dataset.label);
                        }, this);
                                                if (dataset.hidden) {
                                                        // Strikethrough the text if hidden
                                                        ctx.beginPath();
+                                                       ctx.lineWidth = 2;
                                                        ctx.moveTo(this.options.labels.boxWidth + (this.options.labels.fontSize / 2) + cursor.x, cursor.y + (this.options.labels.fontSize / 2));
                                                        ctx.lineTo(this.options.labels.boxWidth + (this.options.labels.fontSize / 2) + cursor.x + textWidth, cursor.y + (this.options.labels.fontSize / 2));
                                                        ctx.stroke();