jQuery UI Widgets Forums Chart stackedcolumn100 and toolTip

This topic contains 4 replies, has 3 voices, and was last updated by  Dimitar 10 years, 2 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • stackedcolumn100 and toolTip #47901

    HangWire
    Participant

    Hey there,

    I’ve got stacked columns with 100% maximum value. Now I want to display a tooltip looking like this:

    #######################
    # displayText         #
    # value               #
    # (value in percent)  #
    #######################

    How do I get the percentage of each part of the stacked column?

    stackedcolumn100 and toolTip #47985

    Dimitar
    Participant

    Hello HangWire,

    To achieve this, you have to access the chart data source and the other values stored there. Here is an example, based on the demo 100% Stacked Columns:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxchart.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                // prepare chart data as an array
                var sampleData = [
                        { Day: 'Monday', Running: 30, Swimming: 0, Cycling: 25 },
                        { Day: 'Tuesday', Running: 25, Swimming: 25, Cycling: 0 },
                        { Day: 'Wednesday', Running: 30, Swimming: 0, Cycling: 25 },
                        { Day: 'Thursday', Running: 35, Swimming: 25, Cycling: 45 },
                        { Day: 'Friday', Running: 0, Swimming: 20, Cycling: 25 },
                        { Day: 'Saturday', Running: 30, Swimming: 0, Cycling: 30 },
                        { Day: 'Sunday', Running: 60, Swimming: 45, Cycling: 0 }
                    ];
    
                // prepare jqxChart settings
                var settings = {
                    title: "Fitness & exercise weekly scorecard",
                    description: "Time spent in vigorous exercise by activity",
                    enableAnimations: true,
                    showLegend: true,
                    padding: { left: 5, top: 5, right: 5, bottom: 5 },
                    titlePadding: { left: 90, top: 0, right: 0, bottom: 10 },
                    source: sampleData,
                    categoryAxis:
                        {
                            text: 'Category Axis',
                            textRotationAngle: 0,
                            dataField: 'Day',
                            showTickMarks: true,
                            tickMarksInterval: 1,
                            tickMarksColor: '#888888',
                            unitInterval: 1,
                            showGridLines: false,
                            gridLinesInterval: 1,
                            gridLinesColor: '#888888',
                            axisSize: 'auto'
                        },
                    colorScheme: 'scheme04',
                    seriesGroups:
                        [
                            {
                                type: 'stackedcolumn100',
                                columnsGapPercent: 100,
                                seriesGapPercent: 5,
                                toolTipFormatFunction: function (value, itemIndex, serie, group, categoryValue, categoryAxis) {
                                    var current = sampleData[itemIndex];
                                    var total = current.Running + current.Swimming + current.Cycling;
                                    return ((value / total) * 100).toFixed(2) + "%";
                                },
                                valueAxis:
                                {
                                    unitInterval: 10,
                                    minValue: 0,
                                    maxValue: 100,
                                    displayValueAxis: true,
                                    description: 'Time in minutes',
                                    axisSize: 'auto',
                                    tickMarksColor: '#888888'
                                },
                                series: [
                                        { dataField: 'Running', displayText: 'Running' },
                                        { dataField: 'Swimming', displayText: 'Swimming' },
                                        { dataField: 'Cycling', displayText: 'Cycling' }
                                    ]
                            }
                        ]
                };
    
                // setup the chart
                $('#jqxChart').jqxChart(settings);
    
            });
        </script>
    </head>
    <body class='default'>
        <div id='jqxChart' style="width: 680px; height: 400px">
        </div>
    </body>
    </html>

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    stackedcolumn100 and toolTip #47997

    HangWire
    Participant

    Thank you very much 🙂
    That’ll me a lot!

    stackedcolumn100 and toolTip #65849

    arunthatham
    Participant

    One Question :
    In stacked column we will have different Stack like running ,swimming,cycling .
    On hovering swimming I should get only display text as “swimming:90” and on hovering cycling i should see “Running:20 “.

    How to Achieve this ??

    stackedcolumn100 and toolTip #65881

    Dimitar
    Participant

    Hello arunthatham,

    Here is how to achieve your requirement using toolTipFormatFunction:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdraw.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxchart.core.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                // prepare chart data as an array
                var sampleData = [
                        { Day: 'Monday', Running: 30, Swimming: 0, Cycling: 25 },
                        { Day: 'Tuesday', Running: 25, Swimming: 25, Cycling: 0 },
                        { Day: 'Wednesday', Running: 30, Swimming: 0, Cycling: 25 },
                        { Day: 'Thursday', Running: 35, Swimming: 25, Cycling: 45 },
                        { Day: 'Friday', Running: 0, Swimming: 20, Cycling: 25 },
                        { Day: 'Saturday', Running: 30, Swimming: 0, Cycling: 30 },
                        { Day: 'Sunday', Running: 60, Swimming: 45, Cycling: 0 }
                    ];
    
                var toolTipCustomFormatFn = function (value, itemIndex, serie, group, categoryValue, categoryAxis) {
                    return serie.displayText + ': ' + value;
                };
    
                // prepare jqxChart settings
                var settings = {
                    title: "Fitness & exercise weekly scorecard",
                    description: "Time spent in vigorous exercise by activity",
                    enableAnimations: true,
                    showLegend: true,
                    padding: { left: 5, top: 5, right: 5, bottom: 5 },
                    titlePadding: { left: 90, top: 0, right: 0, bottom: 10 },
                    source: sampleData,
                    xAxis:
                        {
                            dataField: 'Day',
                            showTickMarks: true,
                            tickMarksInterval: 1,
                            tickMarksColor: '#888888',
                            unitInterval: 1,
                            showGridLines: false,
                            gridLinesInterval: 1,
                            gridLinesColor: '#888888',
                            axisSize: 'auto'
                        },
                    colorScheme: 'scheme06',
                    seriesGroups:
                        [
                            {
                                type: 'stackedcolumn',
                                columnsGapPercent: 100,
                                seriesGapPercent: 5,
                                toolTipFormatFunction: toolTipCustomFormatFn,
                                valueAxis:
                                {
                                    unitInterval: 10,
                                    minValue: 0,
                                    maxValue: 120,
                                    displayValueAxis: true,
                                    description: 'Time in minutes',
                                    tickMarksColor: '#888888'
                                },
                                series: [
                                        { dataField: 'Running', displayText: 'Running' },
                                        { dataField: 'Swimming', displayText: 'Swimming' },
                                        { dataField: 'Cycling', displayText: 'Cycling' }
                                    ]
                            }
                        ]
                };
    
                // setup the chart
                $('#chartContainer').jqxChart(settings);
    
            });
        </script>
    </head>
    <body class='default'>
        <div id='chartContainer' style="width: 850px; height: 500px;" />
    </body>
    </html>

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.