4

如何更改剑道条形图系列标签的定位?考虑以下小提琴:http: //jsfiddle.net/ZPUr4/149/

在图表中,对于正值,条形值位于顶部,对于负值,条形值位于底部。

如何将系列标签值定位在正负值的条形顶部?

即使条形值不同,如何将所有标签值放在同一水平线上?

如果我的问题不清楚,请告诉我。

下面是 HTML 代码:

    <div id="example" class="k-content">
    <div id="chart"></div>
</div>

JS代码:

function createChart() {
        $("#chart").kendoChart({
            title: {
                text: "Site Visitors"
            },
            legend: {
                position: "bottom"
            },
            seriesDefaults: {
                type: "column",
                labels: {
                    visible: true,
                    background: "transparent",

                }
            },
            series: [{
                name: "Total Visits",
                data: series1,
                gap: 1.0,
                spacing: 0
            }, {
                name: "Unique visitors",
                data: series2,
                gap: 1.0
            }],
            valueAxis: {
                min: -200000,
                max: 200000,
                axisCrossingValue: 50000,  
                line: {
                    visible: false
                },
                title: {
                    text: "Availability"
                },

                color: 'blue'
            },
            categoryAxis: {
               color: "blue",
                width: 25,
                majorGridLines: {
                    visible: true,
                    position: "bottom"
                },
                line: {
                    width: 3,
                }
            },
            tooltip: {
                visible: true,
                format: "{0}"
            }
        });
    }

var series1=[56000, 63000, 74000, 91000, 117000, 158000];
var series2= [-52000, 34000, 23000, -98000, 67000, 83000];

    $(document).ready(function () {
        createChart();

        $("#example").bind("kendo:skinChange", createChart);

        var chart = $("#chart").data("kendoChart"),
            firstSeries = chart.options.series;
    });

谢谢。

4

3 回答 3

6

为了指定值在顶部,您应该使用:

labels: {
    visible: true,
    position: "top"
}

但是有了这个,你就可以将数字放在栏内。为了把它移到外面,你需要做:

labels: {
    visible: true,
    position: "top",
    padding: {
        top: -20
    }
}

添加padding.top20pix的地方就足够了。

您的 JSFiddle 在这里修改:http: //jsfiddle.net/OnaBai/ZPUr4/178/

于 2014-06-02T17:18:13.793 回答
0

有点晚了,但也许对您或其他人仍然有用。

我正在对我的网格进行相当多的自定义样式,以下允许我将标签放在图表顶部的同一行上。

function chartBound(e) {
    var chartData = e.sender;
    var oldPrivateRedraw = chartData._redraw;
    if (oldPrivateRedraw.toString().indexOf('Extend') == -1) { //not already extended
        //Extends kendos function so we can do custom styling to svg components etc
        chartData._redraw = function () {
            oldPrivateRedraw.apply(chartData);
            PostGraphDrawEvents();
        };
    }
}
function PostGraphDrawEvents() {
    // Move the labels to the top of the graph
    $.each($('#@chartId svg > g > text[style*="11px"]'), function (index, node) {
        var clonedNode = node.cloneNode(true);
        $(clonedNode).attr('y', 10);
        $(node).before(clonedNode);
    });
}
于 2014-07-01T05:11:43.037 回答
0

标题 ------- 将以等宽字体显示。前四个空格将被删除,但所有其他空格将被保留。

Markdown and HTML are turned off in code blocks:
<i>This is not italic</i>, and [this is not a link](http://example.com)

要创建不是块,而是内联代码跨度,请使用反引号:

字符$只是. window.jQuery如果你想在列表中有一个预先格式化的块,缩进八个空格:

  1. 这是正常的文字。
  2. 这也是如此,但现在遵循一个代码块:

    Skip a line and indent eight spaces.
    That's four spaces for the list
    and four to trigger the code block.
    
于 2017-01-17T02:56:07.963 回答