extjssencha-touchsencha-touch-2sencha-chartssencha-touch-2.1

Sencha Charts Pie label rotation


I'm using the Sencha Touch 2.1 with Charts 1.1 to display some data.

I have a pie chart depicted below:

Pie chart example

I want the labels to stay where they are now , but I want them to be horizontal (not rotated).

extend: 'Ext.chart.PolarChart',
    requires: [
    'Ext.chart.axis.Numeric',
    'Ext.chart.axis.Category',
    'Ext.chart.series.Pie',
    'Charting.store.charts.perStore',
    'Ext.chart.interactions.Rotate'
],
config: {
    colors: ["#6295C7", "#CCCCC", "#FFFFF"],
    store: 'chrtProduct',
    // centered:true,
    // innerPadding:20,
    series: [{
        type: 'pie',
        labelField: 'verdeling',
        label:{
            /*display:'middle',
            orientation:'horizontal',*/
            field:'patVerdeling',
            font: '1em Trade Gothic LT Std Bold',
            contrast:true,
            disableCallout:true
        },
        xField: 'patVerdeling'
        //,rotation:90
    }] 
    //,interactions: ['rotate']

The following code doesn't seem to do anything when uncommented.

display:'middle',
orientation:'horizontal',

Solution

  • Ok, I'm not sure whether this is the best way or not but it works for me, so after spending some time digging into the sencha chart library, the solution is easier then what I expected.

    Just comment this line in PieSlice.js located at touch/src/chart/series/sprite/PieSlice.js of your app project:

    labelCfg.rotationRads = midAngle + Math.atan2(surfaceMatrix.y(1, 0) - surfaceMatrix.y(0, 0), surfaceMatrix.x(1, 0) - surfaceMatrix.x(0, 0));
    

    This line perform as the key role to rotate the label of your pie chart.