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

piechart - binding from request vs file

1 Answer 84 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 12 Dec 2011, 07:45 PM
I have created a simple test from your examples

<!DOCTYPE html>
<head>
    <title></title>
 
    <link href="../Styles/kendo.common.css" rel="Stylesheet" />
    <link href="../Styles/kendo.default.css" rel="Stylesheet" />
    <script src="../Scripts/kendo/jquery.min.js"></script>
    <script src="../Scripts/kendo/kendo.core.js"></script>
    <script src="../Scripts/kendo/kendo.data.js"></script>
    <script src="../Scripts/kendo/kendo.chart.js"></script>
</head>
<body>
           <div id="example" class="k-content">
 
           <div>
                <div id="chart"></div>
            </div>
            <script type="text/javascript">
                function createChart() {
                    $("#chart").kendoChart({
                        theme: $(document).data("kendoSkin") || "default",
                        dataSource: {
                            transport: {
                                read: {
                                    url: "test.json",
                                    dataType: "json"
                                }
                            },
                            sort: {
                                field: "Program",
                                dir: "asc"
                            }
                        },
                        title: {
                            text: "Signup Count"
                        },
                        legend: {
                            position: "bottom"
                        },
                        seriesDefaults: {
                            type: "pie",
                            labels: {
                                template: "${ value } - ${ category }",
                                visible: true
                            }
                        },
                        series: [{
                            field: "SignupCount",
                            categoryField: "Program"
                        }],
                        tooltip: {
                            visible: false
                        }
                    });
                }
 
                $(document).ready(function () {
                    setTimeout(function () {
                        createChart();
 
                        // Initialize the chart with a delay to make sure
                        // the initial animation is visible
                    }, 400);
 
                    $(document).bind("kendo:skinChange", function (e) {
                        createChart();
                    });
                });
            </script>
        </div>
 
</body>
</html>

test.json is a file that contains

[{"AgentsNames":["person 1"],"Program":"GOLD","SignupCount":1},{"AgentsNames":["person 2","person 3"],"Program":"No Program","SignupCount":2}]

that works perfectly

but when I change the url to "datastream.aspx?r=SIGNUPCOUNT" it doesnt work. This page responds with that JSON string

MemoryStream stream = GPCO.JSON.Serialize(stats.Programs);
string response = GPCO.Convert.BytesToUTF8(stream.GetBuffer());
Response.Clear();
Response.ContentType = "application/json";
Response.Write(response);

I've confirmed that it writes 

[{"AgentsNames":["person 1"],"Program":"GOLD","SignupCount":1},{"AgentsNames":["person 2","person 3"],"Program":"No Program","SignupCount":2}]

that is also the source in the browser when I call the page directly. I've tried various parameters in the transport type: "GET" but nothing seems to work. 



1 Answer, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 12 Dec 2011, 07:58 PM
In posting this, I had a second look at how I was coverting the stream to string. memorystream.GetBuffer() is wrong. I put .ToArray() and it worked. GetBuffer returns everything, even null terminated bytes

you can delete if you like

Tags
Data Source
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Share this question
or