This is a migrated thread and some comments may be shown as answers.

Category Label for dynamic stacked column chart

1 Answer 104 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 17 Dec 2013, 04:41 PM
I am building a stacked column chart.  I don't know the number of series going into it so I am using a foreach to build each series.  I want a category label for each of the series.  Typically for something like this I would use the categoryexpression but can't figure out how to do it with the way I am building.  Any help would be appreciated.

@(Html.Kendo().Chart()
    .Name("chart")
    .Theme("flat")
    .Title("Issues Waterfall")
    .DataSource(ds => ds
        .ServerOperation(false)
    )
    .Series(series =>
    {
        series.Column(new double[] { 100 }).Name("Total").Color("Blue").Stack("Total");
 
        foreach (var resp in Model.listResponsibleDowntime)
        {
            series.Column(new double?[] { resp.percent_pad }).Name(resp.resp_name).Color("White").Opacity(0).Labels(false).Tooltip(false).Stack(resp.resp_name);
            series.Column(new double?[] { resp.percent_downtime }).Name(resp.resp_name).Color(resp.resp_color).Labels(lables => lables.Format("{0:n2}%").Visible(true).Position(ChartBarLabelsPosition.OutsideEnd)).Stack(resp.resp_name);
        }
 
        series.Column(new double?[] { Model.oee }).Name("Actual").Color("Green").Stack("Actual").Labels(lables => lables.Format("{0:n2}%").Visible(true).Position(ChartBarLabelsPosition.OutsideEnd));
         
    })
    .CategoryAxis(axis => axis
        .MajorGridLines(lines => lines.Visible(false))
        .Labels(model => model
            .Rotation(0)
            .Visible(true)
        )
        //.Categories(Model.listCategories)
    )
    .Legend(legend => legend
        .Position(ChartLegendPosition.Top)
        .Margin(20, 50, 20, 50)
        .Visible(false)
    )
    .ValueAxis(axis => axis
        .Numeric()
        .Min(0)
        .Max(100)
        .Labels(labels => labels.Format("{0:n0}%"))
    )
    .Tooltip(tooltip => tooltip
        .Visible(true)
        .Template("#= series.name #: #= kendo.format('{0:n2}', value) #")
    )
)

1 Answer, 1 is accepted

Sort by
0
Hristo Germanov
Telerik team
answered on 18 Dec 2013, 12:08 PM
Hi Steve,

In this case you need to pass data like this:  new dynamic[] { new { value = 1, category = "a" } }

Regards,
Hristo Germanov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Charts
Asked by
Steve
Top achievements
Rank 1
Answers by
Hristo Germanov
Telerik team
Share this question
or