2

无论如何要在折线图中隐藏零 (0) 值的数据点?我目前正在使用折线图(剑道),似乎找不到一种简单的方法来做到这一点。基本上一条线出现在图表上的 0 值处,我宁愿根本不显示这条线。线端值之一的数据绑定为零(我必须删除它)。示例数据如 [30,50,40 ,75,0]

这里我提供html代码

 $.ajax({
                type: "POST",
                contentType: "application/json;charset=utf-8",
                url: "dataVizWebService.asmx/GetSellInOfficeTrends",
                dataType: "json",
                success: function (data) {

                    $("#chart").kendoChart({
                        dataSource: {
                            data: data.d,
                            value: "#={0}>0"
                        },
                        legend: {
                            position: "bottom"
                        },
                        title: {
                            text: "Population"
                        },
                        series: [
                                    {
                                        type: "line",
                                        field: "Population2010",
                                        name: "Population2010",
                                        axis: "Year",
                                        color: "#4a7ebb"
                                    }, {
                                        type: "line",
                                        field: "Population2011",
                                        name: "Population2011",
                                        axis: "Year",
                                        color: "#be4b48"
                                    }, {
                                        type: "line",
                                        field: "Population2012",
                                        name: "Population2012",
                                        axis: "Year",
                                        color: "#98b954"
                                    }, {
                                        type: "line",
                                        field: "Population2013",
                                        name: "Population2013",
                                        axis: "Year",
                                        dashType: "dash",
                                        color: "#000000"
                                    }
                                    ],
                        valueAxis: [{
                            name: "Year",
                            title: { text: "Population in Millions" }
                        }],
                        categoryAxis: {
                            field: "Week",
                            majorTickType: "none",
                            labels: {
                                skip: 0
                            }
                        },
                        tooltip: {
                            visible: true
                        }
                    })
                }
            });

任何帮助将不胜感激。

4

2 回答 2

2

Kendoui API 文档中有一个缺失值属性。您可以使用这些属性并检查对您有用的内容。

于 2013-06-11T11:28:16.403 回答
1

您可以连接到dataSource 的parse()并在那里您可以更改将传递给图表的数据。例子:

function parse(items) {
  var item,
      result = [];

  for (var i = 0; i < items.length; i++) {
    item = items[i];
    if (item.value !== 0) {
      result.push(item);
    }
  }

  return result;
}

$(function() {
  var data = [{ value: 30 },{ value: 50 },{ value: 40 },{ value: 75 }, { value: 0 }];
  $("#chart").kendoChart({
    dataSource: {
      data: data,
      schema: {
        parse: parse
      } 
    },
    series: [{
      type: "line",
      field: "value"
    }]
  });
});
于 2013-01-04T10:51:15.173 回答