chart.jspie-chartsimplepie

who know how to put down the title of pie in ionic 2


I want to put the label under the pie.who know please tell me.thank you! here the code.

      this.pieChart = new Chart(this.pieCanvas.nativeElement, {
        type: 'pie',
        data: {
            labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
            datasets: [{
                label: '# of Votes',
                data: [12, 19, 3, 5, 2, 3],
                backgroundColor: [
                    "#ff0000",
                    "#0000ff",
                    "#ffff00",
                    "#008000",
                    "#800080",
                    "#ffa500"
                ]
            }]
        }

    }); 

image


Solution

  • You can achieve this by setting the label / legend 's position.

    options: {
        legend: {
            position: 'bottom'
        }
    }
    

    The full code would be like this ...

    this.pieChart = new Chart(this.pieCanvas.nativeElement, {
        type: 'pie',
        data: {
            labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
            datasets: [{
                label: '# of Votes',
                data: [12, 19, 3, 5, 2, 3],
                backgroundColor: [
                        "#ff0000",
                        "#0000ff",
                        "#ffff00",
                        "#008000",
                        "#800080",
                        "#ffa500"
                    ]
                }]
        },
        options: {
            legend: {
                position: 'bottom'
            }
        }
    });