c3js - 显示在内容顶部的网格线

标签 c3

我一直在尝试使 x 轴网格线位于 c3js 条形图的内容后面。

我玩弄了不起作用的 z-index。我尝试使用不透明度也不起作用。

这是带有我正在使用的代码的 JSFiddle。

https://jsfiddle.net/chaitanya81/rvhb0fy4/1/

var chart = c3.generate({
        bindto: '#chart',
        data: {
            x : 'x',
            columns: [
                ['x', 'M','T','W','TH','F','SA','SU'],
                ['revenue', 200, 300, 200, 400, 500, 700, 600.56]
            ],
            type: 'bar'
        },
        color: {
            pattern: ["#ff9900"]
        },
        axis: {
            x: {
                type: 'category', // this needed to load string x value
                tick: {
                    outer: false
                }
            },
            y: {
                tick: {
                    outer: false
                }
            }
        },
        grid: {
            x: {
                lines: [
                    {value: "M"},
                    {value: "T"},
                    {value: "W"},
                    {value: "TH"},
                    {value: "F"},
                    {value: "SA"},
                    {value: "SU"}
                ]
            }
        },
        bar: {
            width: {
                ratio: 0.4
            }
        },
        legend: {
            hide: true
        },
        tooltip: {
            contents: function (data, defaultTitleFormat, defaultValueFormat, color) {
                    var $$ = this, config = $$.config,
                        titleFormat = config.tooltip_format_title || defaultTitleFormat,
                        nameFormat = config.tooltip_format_name || function (name) { return name; },
                        valueFormat = config.tooltip_format_value || defaultValueFormat,
                        text, i, title, value;

                        for (i = 0; i < data.length; i++) {
                            if (! (data[i] && (data[i].value || data[i].value === 0))) { continue; }

                            if (! text) {
                              title = titleFormat ? titleFormat(data[i].x) : data[i].x;
                              text = "<div id='tooltip' class='d3-tip'>";
                            }
                            value = valueFormat(data[i].value, data[i].ratio, data[i].id, data[i].index);
                            text += "<span class='value'>$" + value + "</span>";
                            text += "</div>";
                        }

                    return text;
            }
        },
        transition: {
            duration: 1000
        }
});

有人用 c3js 图表试过这个吗?

提前致谢。

最佳答案

您可以将 grid.lines.front 设置为 false

var chart = c3.generate({
    bindto: '#chart',
    data: {
      ...
    },
    grid: {
      lines: {
        front: false
      }
    }
  });

https://jsfiddle.net/Yosephsol/bwu70xgq/

关于c3js - 显示在内容顶部的网格线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31347610/

相关文章:

javascript - 如何在 c3 图表中创建刻度线

javascript - c3.js 生成图表后更改颜色模式

javascript - 在 .generate() 之后和 .load() 之前将参数传递给 c3js 工具提示

javascript - c3.generate 不抛出错误

javascript - 如何使用 c3.js 在工具提示标题中显示每列的总数?

d3.js - 如何从 d3 饼图中删除光标指针

javascript - c3js json 时间序列问题

javascript - C3 js折线图获取日期错误

javascript - c3js - D3js - 在简单的条形图中自定义标签

javascript - 使用基于下拉列表的更新图表