【问题标题】:jQuery Sparklines - Tooltip in Stacked Bar ChartjQuery Sparklines - 堆积条形图中的工具提示
【发布时间】:2016-01-06 08:06:19
【问题描述】:

使用jQuery Sparklines v2.1.2,我正在创建一个堆叠条形图

工具提示值显示正确。它将每个小块的列名称显示为工具提示。我应该如何为每个小块自定义工具提示?

tooltipFormat: '{{offset:offset}} - {{value}}',
  tooltipValueLookups: {
    'offset': {
      0: 'India',
      1: 'France',
      2: 'USA'
    }

源代码位于:http://jsfiddle.net/Hj6fB/236/

【问题讨论】:

    标签: sparklines


    【解决方案1】:

    如果您仍在寻找解决方案。

    这对我有用https://groups.google.com/forum/#!topic/jquery-sparkline/XcigtHeVx3M

    $('#StackedBarChart').sparkline([
          [1, 4, 2],
          [2, 3, 2],
          [3, 2, 2],
          [4, 1, 2]
        ], {
          type: 'bar',
          // Map the offset in the list of values to a name to use in the tooltip
          myPrefixes: ['USA', 'France','India'],
                    tooltipFormatter: function(sp, options, fields) {
                        var format =  $.spformat('<div class="jqsfield"><span style="color: {{color}}">&#9679;</span> {{myprefix}} {{value}}</div>');
                        var result = '';
                        $.each(fields, function(i, field) {
                                field.myprefix = options.get('myPrefixes')[i];
                                result += format.render(field, options.get('tooltipValueLookups'), options);
                        })
                        return result;
                    },
    
          height: "75px",
          barWidth: "30px",
        });
    

    查看示例 http://jsfiddle.net/Hj6fB/241/

    【讨论】:

    • 你声明的函数中的sp、options、fields是什么?为它们分配了哪些值?
    猜你喜欢
    • 1970-01-01
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多