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

Legend not being displayed

2 Answers 318 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 01 Jun 2016, 06:24 PM

<div class="chart-cell">
    <div id="chart" />
</div>

$.get("/chart/GetCustomPlotData", data, function (response) {
    if (response.Success) {
        var result = response.Result;
 
        if (result.IsAggregated) {
            $("#data-point-count").text(result.DataSet.ChannelData[0].Data.length + " of " + result.DataSet.DataPointsInFile);
        }
        else {
            $("#data-point-count").text(result.DataSet.ChannelData[0].Data.length);
        }
 
        // Format the data then generate the graphs
        var seriesData = [];
        for (var i = 0; i < result.DataSet.ChannelData.length; ++i) {
            var data = []
            for (var j = 0; j < result.DataSet.ChannelData[i].Data.length; ++j) {
                data[j] = { Time: new Date(FormatUtsDate(result.DataSet.ChannelData[i].Data[j].Time)), Value: result.DataSet.ChannelData[i].Data[j].Value }
            }
 
            seriesData[i] = {
                name: result.DataSet.ChannelData[i].Title !== "" ? result.DataSet.ChannelData[i].Title : result.DataSet.ChannelData[i].ChannelName,
                visibleInLegend: false,
                tooltip: {
                    template: "value: #= value.y #, time: #= FormatDate(value.x) #",
                    visible: true
                },
                type: "scatterLine",
                xField: "Time",
                yField: "Value",
                data: data,
                markers: {
                    visible: false
                }
            }
        }
 
        $("#chart").kendoChart({
            series: seriesData,
            chartArea: {
                @* There is probably a better way to do this, but I can't think of it right now.
                This occurs before the divs are rendered so their widths at this point are not
                what they will be after rendering *@
                //width: 1074
            },
            xAxis: [{
                type: "date",
                baseUnit: "seconds",
                labels: {
                    step: (result.Columns == 3 ? 2 : 1)
                }
            }],
            yAxis: [{
                axisCrossingValue: [-50000]
            }],
            legend:{
                position: "left",
                orientation: "horizontal",
                visible: true
            },
            pannable: true,
            zoomable: true,
        });
 
        kendo.ui.progress($(".chart-loading"), false);
        $("#loading").hide();
        $("#nine-blocker-grid").show();
    }
    else {
        kendo.ui.progress($(".chart-loading"), false);
        $("#loading").hide();
        $("#error-message").text(response.Message);
        $("#error").show();
    }
});

All the series are being plotted, but for whatever reason the legend does not display. Just wonder if there is any obvious reason why that might be

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 03 Jun 2016, 10:22 AM
Hello Chris,

The legend will not be shown because the visibleInLegend option is set to false in the series configuration:
seriesData[i] = {
    name: result.DataSet.ChannelData[i].Title !== "" ? result.DataSet.ChannelData[i].Title : result.DataSet.ChannelData[i].ChannelName,
    visibleInLegend: false,
    ...


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Chris
Top achievements
Rank 1
answered on 03 Jun 2016, 11:33 AM

The dreaded pitfall of copy/paste.

Thanks for the help.

Tags
Charts
Asked by
Chris
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Chris
Top achievements
Rank 1
Share this question
or