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

Binding XML data in to Chart

2 Answers 81 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Asat
Top achievements
Rank 1
Asat asked on 21 May 2014, 06:13 AM
Hi 

I am trying to display a remote XML data in a bar chart. Below is my code. 

<script type="text/javascript">
        $(document).ready(function() {
            $("#chart").kendoChart({
                dataSource: {
                    transport: {
                        read: {
                            url: "asat.xml",
                            dataType: "xml"
                        }
                    },
                    schema: {
                      type: "xml",
                      data: "/cCRMGetForecastByStageResponse/ForecastStages/ForecastStage",
                      model: {
                        fields: {
                          opportunitycount: "opportunitycount/text()",
                          leadscount: "leadscount/text()",
                          description: "description/text()"
                        }
                      }
                    }         
                },
                title: {
                    text: "Forecast Count by Stage"
                },
                legend: {
                    position: "top"
                },
                seriesDefaults: {
                    type: "column"
                },
                series:
                [{
                    field: opportunitycount,
                    name: "Opportunities"
                }, {
                    field: leadscount,
                    name: "Leads"
                }],
                categoryAxis: {
                    field: "description",
                    labels: {
                        rotation: -90
                    },
                    majorGridLines: {
                        visible: false
                    }
                },
                valueAxis: {
                    labels: {
                        format: "N0"
                    },
                    majorUnit: 1,
                    line: {
                        visible: false
                    }
                },
                tooltip: {
                    visible: true,
                    format: "N0"
                }
            });    
        });
    </script>


My XML is as below,

<?xml version="1.0"?>
<cCRMGetForecastByStageResponse xmlns="http://www.pronto.net/crm/1.0">
  <ForecastStages>
    <ForecastStage>
      <description>Initial Stage</description>
      <opportunycount>2</opportuny-count>
      <opportunyamount>1256</opportuny-amount>
      <leadscount>0</leads-count>
      <leadsamount>0</leads-amount>
    </ForecastStage>
    <ForecastStage/>
    <ForecastStage>
      <description>First Stage</description>
      <opportunitycount>1</opportunitycount>
      <opportunyamount>100</opportuny-amount>
      <leadscount>1</leadscount>
      <leadsamount>80000</leads-amount>
    </ForecastStage>
  </ForecastStages>
</cCRMGetForecastByStageResponse >


When I run it, an error comes saying opportunitycount is not defined. 

When I use the same data in a json (without the schema section above), it works. 

Is there a way to directly bind XML elements in series section? 

Thanks in advance,
Ishan

PS: I personally think your example should cover XML data binding as well. Almost all examples are based on JSON.

2 Answers, 1 is accepted

Sort by
0
Accepted
T. Tsonev
Telerik team
answered on 22 May 2014, 01:47 PM
Hello,

The XML you provided appears to be invalid, more specifically the closing tags do not match the opening tags - opportunitycount / opportuny-count.
You may handle the data source error event to notified for such problems.

Regards,
T. Tsonev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Asat
Top achievements
Rank 1
answered on 23 May 2014, 10:19 AM
Sorry , that solved the problem I had.
Tags
Charts
Asked by
Asat
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Asat
Top achievements
Rank 1
Share this question
or