Creating a Piechart in Kendo UI that is bound to hierarchal remote data

I am facing an issue with binding remote data to a pie chart while managing a grid with dropdown sorting options. The grid is working fine, but I am unable to display the hierarchical data on the pie chart as categories.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" href="styles/kendo.common.min.css" />
    <link rel="stylesheet" href="styles/kendo.default.min.css" />
    <script src="js/jquery.min.js"></script>
    <script src="js/kendo.all.min.js"></script>
</head>
<body>
<div id="project">
    <div id="grid"></div>
    <div id="chart"></div>
    <script type="text/x-kendo-template" id="template">
        <div class="toolbar">
            <label class="category-label" for="category">Show products by category:</label>
            <input type="search" id="category" style="width: 150px"/>
         </div>
    </script>
    <script>
        $(document).ready(function() {
            //Grid displays all products or products from one category, which set from dropdown list
            var grid = $("#grid").kendoGrid({
                dataSource: {
                    type: "odata",
                    transport: {
                        read: "//demos.telerik.com/kendo-ui/service/Northwind.svc/Products"
                    },
                    pageSize: 20,
                    serverPaging: true,
                    serverSorting: true,
                    serverFiltering: true
                },
                toolbar: kendo.template($("#template").html()),
                height: 550,
                sortable: true,
                pageable: true,

                dataBound:function(){
                    var grid = this;
                    $.each(grid.tbody.find('tr'),function(){
                        var model = grid.dataItem(this);
                        if(model.Discontinued==true){
                            $('[data-uid='+model.uid+']').addClass('k-state-selected');
                        }                          
                    });
                },

                columns: [
                   // { field: "ProductID", title: "Product ID", width: 100 },
                    { field: "ProductName", title: "Product Name", template: '#=kendo.format(ProductName.toUpperCase())#' },
                    { field: "UnitPrice", title: "Price", width: 150, template: 'EUR #: kendo.format("{0:c}", UnitPrice)#' },
                    { field: "UnitsInStock", title: "In Stock", width: 150 },
                    { field: "Discontinued", title: "Discontinued", width:50 },
                    { field: "QuantityPerUnit", title: "Quantity" }
                ]
            });
            //DropDown list for sorting by the category
            var dropDown = grid.find("#category").kendoDropDownList({
                dataTextField: "CategoryName",
                dataValueField: "CategoryID",
                autoBind: false,
                optionLabel: "All",
                dataSource: {
                    type: "odata",
                    severFiltering: true,
                    transport: {
                        read: "//demos.telerik.com/kendo-ui/service/Northwind.svc/Categories"
                    }
                },
                change: function() {
                    var value = this.value();
                    if (value) {
                        grid.data("kendoGrid").dataSource.filter({ field: "CategoryID", operator: "eq", value: parseInt(value) });
                  } else {
                    grid.data("kendoGrid").dataSource.filter({});
                 }
             }
         });

      var data = [
              {
                "source": "Hydro",
                "percentage": 20,
              },
              {
                "source": "Hydro",
                "percentage": 20
              },
              {
                "source": "Solar",
                "percentage": 10
              },
              {
                "source": "Nuclear",
                "percentage": 30            
            }
          ];

          var dataSource = new kendo.data.DataSource({
             data: data,
              group: {field: "source", aggregates: [{
               field: "percentage", aggregate: "sum"
             }]}
          });
          dataSource.read();

          function getChartData() {
              var chartData = [];
              var view = dataSource.view();
              for(var idx = 0; idx < view.length; idx++) {
                  chartData.push({
                  source: view[idx].value,
                  percentage: view[idx].aggregates.percentage.sum
                  });
              }
              return chartData;
            } 
          //From This piechart I want to sorting grid
          var chart = $("#chart").kendoChart({
              title: {
                text: "Categories and Products"
              },
              legend: {
                position: "bottom"
              },


              dataSource: {
                  transport: {
                      read: function(e) {
                        e.success(getChartData());
                      }
                  }
              },
              series: [{
                  type: "pie",
                  field: "percentage",
                  categoryField: "source",
                  explodeField: "explode",
                  aggregate: "count",
                  labels: {
                      visible: true,
                      background: "transparent",
                      template: "#= category #: \n #= value#%"
                  }
              }],

              seriesClick: function(e){
                  $.each(e.sender.dataSource.view(), function() {
                      // Clean up exploded state
                      this.explode = false;
                  });

                  // Disable animations
                  e.sender.options.transitions = false;

                  // Explode the current slice
                  e.dataItem.explode = true;
                  e.sender.refresh();
              }
          });
      });
    </script>
    <style>
        #grid .k-grid-toolbar
        {
            padding: .6em 1.3em;
        }
        .category-label
        {
            vertical-align: middle;
            padding-right: .5em;
        }
        #category
        {
            vertical-align: middle;
        }
        .toolbar {
            float: center;
        }
    </style>
</div>

Answer №1

I am experienced in connecting a kendo pie chart to remote data sources, having successfully implemented this feature numerous times before. For a demonstration on how to accomplish this task, please refer to the link provided below.

Kendo pie chart - remote binding

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to establish connection via web socket with SSL and WSS in JavaScript

Below is the code I used to implement web socket: try { console.log('wss://' + hostname + ':' + port + endpoint); webSocket = new WebSocket(webSocketURL); webSocket.onmessage = function (event) { //c ...

"Object.entries seems to be returning only the initial object in the list

This is my object var obj = { "first_obj": { "a":1, "status": 1 }, "second_obj": { "a":2, "status": 3 } } I'm struggling to loop through this object using foreach and Object.entries, as the latter only returns the first object. How ...

Create a dynamic HTML page using JavaScript

When I click on the following links: How can I create a new page using JavaScript? Create and dynamically append elements I'm looking to dynamically add HTML elements with JavaScript within a div, but I don't want my code to become overly comp ...

`Need help setting the active class for a bootstrap navbar using Angular JS?`

In my bootstrap navbar, I have the following menu items: Home | About | Contact I'm looking to assign the active class to each menu item based on the current angular route. Specifically, how can I set class="active" when the angular route is at # ...

Searching for a div table using XPATH in Python

Struggling to extract data from a table using Selenium in Python. Any suggestions on how to achieve this? https://i.stack.imgur.com/rPlKR.png <div class="js--property-table-body project-property-table__body"> <span aria-hidden=&quo ...

What is the best way to ensure that my program runs nonstop?

Is there a way to have my program continuously run? I want it to start over again after completing a process with a 2-second delay. Check out my code snippet below: $(document).ready(function () { var colorBlocks = [ 'skip', 'yell ...

Can you explain the contrast between 'depict' and 'examine' when using Jest?

I am currently diving into the world of unit testing in Vue.js with Jest. One question that keeps popping up is when to use describe and when to use test ? TodoApp.vue Component : <template> <div> <h1>TodoApp Componenent</h1> ...

The scrollbar CSS appears to be missing on iPhone browsers Chrome and Safari

After spending the entire day searching for a solution to override the irritating scrollbar issue on my iPhone, I came across this simple example: .scroller { background: lightblue; height: 1000px; max-width: 400px; margin: 90px auto; padding: ...

What is the best way to utilize ajax and javascript for creating a dynamic image gallery on a website

I am looking to create an image portfolio that launches when a user presses a thumbnail. The code for building the portfolio only executes upon pressing the thumbnail. Here is my current setup. Essentially, I want to incorporate something like this into m ...

Update the promise status to reflect any changes

While attempting to modify the button text based on the promise status, I created a custom directive for this purpose. Below is the code snippet for my custom directive: .directive('myDir',function(){ return { scope: { ...

Combining and organizing Javascript files for efficient loading and reusable code functionality

I've been tasked with cleaning up a project that contains around 45-50 separate .js javascript files. I'm trying to figure out the most effective way to reduce their loading size. Should I combine all the files into one using npm or gulp? Or shou ...

What is the most effective way to handle DOM events in Angular 8?

Looking to listen for the 'storage' event from the window in Angular 8. What is the recommended approach to achieving this in Angular? window.addEventListener('storage', () => { }); One method involves using Renderer2, but are ther ...

Display a fancy slideshow that transitions to five new images when the last one is reached

Here is a screenshot of my issue: https://i.stack.imgur.com/duhzn.png Incorporating Bootstrap 3 and FancyBox, I am facing an issue with displaying images in rows. When I reach the last image, clicking on the right arrow should result in sliding to anothe ...

Steps for inserting a button within a table

Currently, I have implemented a function that dynamically adds the appropriate number of cells to the bottom of my table when a button is clicked. This is the JavaScript code for adding a row: <a href="javascript:myFunction();" title="addRow" class= ...

Tips for enabling/disabling a Chrome extension through the utilization of local storage in the background page

Even after reading numerous answers on similar questions, I am still facing some difficulties. My goal is to allow the user to disable my chrome extension by simply clicking on the icon at any time. The extension is designed to run once on every page load, ...

"Learn the art of refreshing data in AngularJS following the use of $emit event handling

I am in need of assistance with AngularJS. How can I re-initialize a variable in scope after using emit? Here is an example code snippet: $scope.uiConfig = {title: "example"}; $scope.$emit('myCustomCalendar', 'Data to send'); $scop ...

Reorganize the JSON data to match the specified format

{ "EUR": { "Description": "", "Bid": "1.1222", "Region": "", "Bid1": "1.1283", "CurrencyCode": "EUR", "FeedSource": "1", "Ask": "1.1226", "ProviderName": "TEST 1", "Low": "1.1195", ...

What changes can be made to the HTML structure to ensure that two form tags function separately?

Hey there! I'm currently tackling a web project that involves incorporating two form tags on one page, each with its own distinct purpose. Nevertheless, it appears that the inner form tag isn't behaving as it should. My suspicion is that this iss ...

How to Find a Specific File by Partial Name in HTML

Currently building a webpage, I need to provide a link to a log file located on the server. The catch is that the filename includes a random number at the end, but I do know the starting part of it. Here's the snippet of my code: <a href="../New_f ...

How to perfectly center an element with a specified aspect ratio

I am experiencing a strange problem when attempting to center an element with aspect-ratio applied. I thought it would work similar to centering an image, but I keep getting stuck with an element of 0px x 0px. https://codepen.io/richardcool/pen/xxeKOwp I ...