【问题标题】:Kendo Bar chart with grouped data with one list and line based on different list具有分组数据的 Kendo 条形图,带有一个列表和基于不同列表的行
【发布时间】:2015-08-25 12:50:43
【问题描述】:

我有一个剑道图表,其中我有从一月到六月的数据,其中有多个位置。例如,Jan 使用 A,B,Total 作为位置,Feb 使用 A,B,Total。现在我必须显示带有位置的条形图和总计的折线图。为了显示条形图,我们必须按位置分组,因此对于线也显示所有位置。你能帮我解决这个问题吗?我必须绘制没有位置的折线图,它应该像每个月一样。

@(Html.Kendo().Chart(Model.CertifiedIronProductionReports)
 @(Html.Kendo().Chart(Model.CertifiedIronProductionReports)
                                .Name("CertifiedIronProduced")
                                .Legend(legend => legend
                                .Visible(true)
                                .Position(ChartLegendPosition.Top)
                                )
                                .ChartArea(chartArea => chartArea
                                .Background("transparent")
                                )
            .DataSource(datasource => datasource
                .Group(group => group.Add(model => model.Location))
                .Sort(sort => sort.Add(model => model.Month))
            )
                                .Series(series =>
                                {
                                    series.Column(Model.CertifiedIronProductionReports).CategoryField("Month").Field("IronCount");
                                })
                                .Series(series =>
                                {
                                    series.Line(Model.CertifiedIronProductionReports).CategoryField("Month").Field("Total").Axis("TotalAxis");
                                })
                                .CategoryAxis(axis => axis
                                    .Categories(categories => categories.Month)
                                    .AxisCrossingValue(0, 20)
                                )
                                .ValueAxis(axis => axis
                                .Numeric()
                                .Line(line => line.Visible(false))
                                .MajorGridLines(lines => lines.Visible(true))
                                )
            .ValueAxis(axis => axis
            .Numeric("TotalAxis")
            .Line(line => line.Visible(false))
            .MajorGridLines(lines => lines.Visible(true))
            )
                                .Tooltip(tooltip => tooltip
                                .Visible(true)
                                .Template("#= series.name #: #= value #")
                                )
                            )

[{"lstTotal":null,"Location":"Tomball","IronCount":383,"Month":"Jan-2015","Total":0},{"lstTotal":null," Location":"Average","IronCount":413,"Month":"Jan-2015","Total":0},{"lstTotal":null,"Location":"Grand Junction","IronCount": 443,"月":"2015 年 1 月","总计":0},{"lstTotal":null,"位置":"总计","IronCount":0,"月":"2015 年 1 月", "Total":826},{"lstTotal":null,"Location":"Tomball","IronCount":180,"Month":"Feb-2015","Total":0},{"lstTotal": null,"Location":"Average","IronCount":280,"Month":"Feb-2015","Total":0},{"lstTotal":null,"Location":"Grand Junction"," IronCount":381,"Month":"Feb-2015","Total":0},{"lstTotal":null,"Location":"Total","IronCount":0,"Month":"Feb- 2015","总计":561}]

【问题讨论】:

  • 你能附上你的 json 数据的例子和你到目前为止尝试过的代码吗?
  • 嗨 Ezanker,我已经添加了我尝试过的代码。请帮我解决这个问题

标签: kendo-ui kendo-chart


【解决方案1】:

如果您将每个月除一个条目之外的所有条目的总计更改为 null,则不会显示额外的行:

[
 {"lstTotal":null,"Location":"Tomball","IronCount":383,"Month":"Jan-2015","Total":null},
 {"lstTotal":null,"Location":"Average","IronCount":413,"Month":"Jan-2015","Total":null},
 {"lstTotal":null,"Location":"Grand Junction","IronCount":443,"Month":"Jan-2015","Total":null},
 {"lstTotal":null,"Location":"Total","IronCount":0,"Month":"Jan-2015","Total":826},
 {"lstTotal":null,"Location":"Tomball","IronCount":180,"Month":"Feb-2015","Total":null},
 {"lstTotal":null,"Location":"Average","IronCount":280,"Month":"Feb-2015","Total":null},{"lstTotal":null,"Location":"Grand Junction","IronCount":381,"Month":"Feb-2015","Total":null},
 {"lstTotal":null,"Location":"Total","IronCount":0,"Month":"Feb-2015","Total":561}
]

var dsCertpData = new kendo.data.DataSource({
    data: certData,
    group: {
        field: "Location",
    },
    sort:{       
        field :"Month",
        dir:"asc"
    }
});  

$("#chart1").kendoChart({
        dataSource: dsCertpData,
        legend: {
          position: "top",
          visible: true,
        },
        seriesColors: ["#00B0F0", "#E29B2C","#A05FCF","#3F890D"],
        series: [
          {
            type: "column",
            categoryField: "Month",
            field:"IronCount",
            stack: true
          },
          {
            type: "line",
            categoryField: "Month",
            field:"Total",
            visibleInLegend: false,
          }        
        ],
        tooltip: {
            visible: true,
            template: "${series.name} : ${value}"
        }
    });

DEMO

注意:您当前正在将月份排序为字符串,因此 Feb 按字母顺序排在 Jan 之前。您需要将架构设置为使用实际日期字段来正确排序。

【讨论】:

  • 非常感谢您的快速回复。我会试试这个,如果我遇到任何问题,我会告诉你。
  • 您好,ezanker,您对图表导出有任何想法吗?
  • 我必须从 javascript 端导出剑道图表图像,但我发现它的代码会显示弹出窗口以保存图像但我想将图像存储在特定路径中而不询问保存然后将图像导出到 excel 中,然后将一些数据与图像一起添加到 Excel 中的另一张工作表中。请帮助我如何实现此功能。因为在我弹出它之后它没有击中控制器。
  • @SamanthKolisetty,我真的不知道。您是否使用 ooxml 类创建 excel 工作簿:docs.telerik.com/kendo-ui/api/javascript/ooxml/workbook
  • 不,我正在尝试在控制器端使用响应写入。
猜你喜欢
  • 2019-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-02
  • 2021-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多