javauser
javauser

Reputation: 101

Scrollable Stacked Column Chart using highcharts?

I need a stacked column chart to be created to display the data captured for a requirement as below.

Show the hours worked by an employee against different projects (Project1,Project2, Project3).

I tried to use Highcharts. When I tried to enable the Scrollable feature for the chart, as there can more number of employees, the labels (employee names) are not getting displayed in the X-axis.

Also, the scrolling seems to be incorrect.

Can anyone help me on making this chart scrollable and also show the employee names as labels on X-Axis.

I have shared the chart I have created so far in ,

http://jsfiddle.net/sri421/Yyq5N/1/

The code is also as below, $(function() { $('#container').highcharts('StockChart', {

    chart: {
        type: 'column',
        inverted:true
    },
      title: {
            text: 'Total Hours worked Vs Different Projects'
        },
      xAxis: {
            categories: ['user1', 'user2', 'user3', 'user4', 'user5','user6', 'user7', 'user8', 'user9', 'user10','user11', 'user12', 'user13', 'user14', 'user15','user16', 'user17', 'user18', 'user19', 'user20'],
             labels: {
                rotation: -45,
                align: 'right',
                style: {
                    fontSize: '13px',
                    fontFamily: 'Verdana, sans-serif'
                }
            }

        },
    yAxis: {
            min: 0,
            title: {
                text: 'Total Hours Worked'
            },
            stackLabels: {
                enabled: true,
                style: {
                    fontWeight: 'bold',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'red'
                }
            }
        },

        plotOptions: {
            column: {
                stacking: 'normal'

            }
        },
    scrollbar: {
        enabled:true

    },

    rangeSelector: {
        enabled: false
    },

    series: [{
            name: 'Project1',
            data: [5, 3, 4, 7, 2,5, 3, 4, 7, 2 ,5, 3, 4, 7, 2,5, 3, 4, 7, 2]
        }, {
            name: 'Project2',
           data: [2, 2, 3, 2, 1,5, 3, 4, 7, 2, 5, 3, 4, 7, 2,5, 3, 4, 7, 2]
        }, {
            name: 'Projecct3',
            data: [3, 4, 4, 2, 5,5, 3, 4, 7, 2, 5, 3, 4, 7, 2,5, 3, 4, 7, 2]
        }]
});

}); Thanks, Sri

Upvotes: 0

Views: 1722

Answers (1)

zeroin
zeroin

Reputation: 6025

You can do scrollable/stacked column chart with amCharts: http://jsfiddle.net/zeroin/mmmv2/

The code:


    AmCharts.ready(function () {
    var chartData = [
        {category:"user1", val1:1, val2:1, val3:1},
        {category:"user2", val1:2, val2:1, val3:2},
        {category:"user3", val1:1, val2:1, val3:4},
        {category:"user4", val1:2, val2:1, val3:2},
        {category:"user5", val1:1, val2:1, val3:5},
        {category:"user6", val1:2, val2:1, val3:2},
        {category:"user7", val1:1, val2:1, val3:3},
        {category:"user8", val1:2, val2:1, val3:1},
        {category:"user9", val1:1, val2:1, val3:3},
        {category:"user10", val1:2, val2:1, val3:4},
        {category:"user11", val1:1, val2:1, val3:3},
        {category:"user12", val1:2, val2:1, val3:3},
        {category:"user13", val1:1, val2:1, val3:3},
        {category:"user14", val1:2, val2:1, val3:1}
    ];

    var chart = new AmCharts.AmSerialChart();
    chart.pathToImages = "http://www.amcharts.com/lib/images/";
    chart.dataProvider = chartData;
    chart.categoryField = "category";

    var valueAxis = new AmCharts.ValueAxis();
    valueAxis.stackType = "regular";
    valueAxis.totalText = "[[total]]";
    chart.addValueAxis(valueAxis);

    var graph1 = new AmCharts.AmGraph();
    graph1.valueField = "val1";
    graph1.type = "column";
    graph1.fillAlphas = 1;
    chart.addGraph(graph1);

    var graph2 = new AmCharts.AmGraph();
    graph2.valueField = "val2";
    graph2.type = "column";
    graph2.fillAlphas = 1;
    chart.addGraph(graph2);

    var graph3 = new AmCharts.AmGraph();
    graph3.valueField = "val3";
    graph3.type = "column";
    graph3.fillAlphas = 1;
    chart.addGraph(graph3); 

    var chartScrollbar = new AmCharts.ChartScrollbar();
    chart.addChartScrollbar(chartScrollbar);

    chart.write("chartdiv");
});

Upvotes: 0

Related Questions