vendredi 10 juin 2016

Working with multiple axis with highcharts.js


I’m working with highcharts.js and I have a scatter plot example I found, fiddle here. With this example I can break down the X-axis into two categories which is ideal for my situation. However, I would like to rotate the labels for each ‘Vendor’ variable 90 degrees while keeping the ‘date’ variable horizontal. I can’t figure this out, of even know if it’s possible. I know how to rotate both variables but that doesn’t look good. Is it even possible to achieve this effect with highcharts.js?

 var cates = [{
                    name: "1/1/2014",
                    categories: ["Vendor 1", "Vendor 2", "Vendor 3"]
                }, {
                    name: "1/2/2014",
                    categories: ["Vendor 1", "Vendor 2", "Vendor 3"]
                }, {
                    name: "1/3/2014",
                    categories: ["Vendor 1", "Vendor 2", "Vendor 3"]
                }];

               console.log("here: ", cates);

$(function () {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: "container",
            type: "scatter",
            borderWidth: 5,
            borderColor: '#e8eaeb',
            borderRadius: 0,
            backgroundColor: '#f7f7f7'
        },
        title: {
             text: "title"
        },
        yAxis: [{ // Primary yAxis
            labels: {
                format: '${value}',
                style: {
                    color: Highcharts.getOptions().colors[0]
                }
            },
            title: {
                text: 'Daily Tickets',
                style: {
                    color: Highcharts.getOptions().colors[0]
                }
            }
        }, { // Secondary yAxis
            title: {
                text: 'Invoices',
                style: {
                    color: Highcharts.getOptions().colors[0]
                }
            },
            labels: {
                format: '${value}',
                style: {
                    color: Highcharts.getOptions().colors[0]
                }
            },
            opposite: true
        }]
        ,
        series: [{
            name: 'Daily',
            type: 'scatter',
            yAxis: 1,
            data: [4, 14, 18, 5, 6, 5, 14, 15, 18],
            tooltip: {
                valueSuffix: ' mm'
            }
        }],
        xAxis: {
            categories: cates,
           /** UNCOMMENT BELOW **/
           // labels: {
           //   rotation:-90,
           //   style: {
           //       fontSize:'10px',
           //       fontWeight:'normal',
           //       color:'#333'
           //   },
           //}
        }
    });
});

UPDATE: I figured it out, the labels object should look like this

labels: {
  groupedOptions: [{
    y: 90,
    rotation: 0
  }],
    rotation:-90,
    style: {
        fontSize:'10px',
        fontWeight:'normal',
        color:'#333'
    },
}

Aucun commentaire:

Enregistrer un commentaire