`Generating Interactive Pie Charts with ASP.NET`

After receiving a helpful suggestion from Gthompson83 about using jqPlot, I am facing a new issue...

The current javascript code on my page (the data is just temporary):

function CreatePie(div) {        
        var data = [
          ['Heavy Industry', 12], ['Retail', 9], ['Light Industry', 14],
          ['Out of home', 16], ['Commuting', 7], ['Orientation', 9]
        ];
        var plot2 = jQuery.jqplot(div, [data],
          {
              seriesDefaults: {
                  renderer: jQuery.jqplot.PieRenderer,
                  rendererOptions: {
                      // Turn off filling of slices.
                      fill: false,
                      showDataLabels: true,
                      // Add a margin to seperate the slices.
                      sliceMargin: 4,
                      // stroke the slices with a little thicker line.
                      lineWidth: 5
                  }
              },
              legend: { show: true, location: 'e' }
          }
        );
    }

I trigger the function from the asp.net code-behind page as a startup script, in this manner:

string script = string.Format("CreatePie('{0}')", "chartDiv" + k,);
ClientScript.RegisterStartupScript(GetType(), "pieChart"+k,
                                   "<script>" + script + "</script>");

The single argument passed is the div where the chart will be placed. Now my question is, how can I pass the data variables so they can be inserted into the

data = [[var1, value1], [var2, value2]...]
part of the Javascript code?

Answer №1

Consider incorporating jqPlot, a JavaScript-based solution, into your project. Utilize asp.net to generate the data needed for the JavaScript variable.

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

Best practices for handling user-submitted files in an ASP.NET web application

I'm embarking on my first web app project that involves processing user uploaded files, and I have a few questions about the standard procedures: When it comes to security, should I be concerned about any potential vulnerabilities? The files my ap ...

Using Sencha Touch for asynchronous HTTP request to Model-View-Controller

Ext.util.JSONP.request({ url: '/Home/GetMessagesMobile', callbackKey: 'callback', params: { lat: geoip_latitude(), lng: geoip_longitude(), ...

Utilize AJAX to invoke a PHP function through JavaScript

I am trying to call a PHP function from Javascript without using jQuery. The PHP function I want to call is: <?php function helloworld() { echo 'Hello Ashish Srivastava'; } ?> It is located in the hello.php file. My Javascript code ...

Exploring the Power of Filtering Arrays in JavaScript

Currently, I am enrolled in online JavaScript courses and I'm intrigued by a particular task: In this task, we are given an initial array (the first argument in the destroyer function) followed by one or more arguments. The goal is to eliminate all e ...

ReactJS: Trouble encountered while parsing information from JSON data

Currently, I am facing an issue while trying to pass data from my JSON file to my ReactJS application. The error message that I am encountering is as follows: TypeError: Cannot read property 'mainPage' of undefined Upon console.logging siteDa ...

Passing the value of the selected calendar date to the controller

How can I pass the value generated by this calendar_date_select to the controller? Any suggestions on how to modify the onchange code? <%= calendar_date_select_tag "meeting_date_1", @time, :embedded => true, :time => true, :minut ...

Switching the Date Property of a Mongo Document using Just One Query

Is there a simple way to update a single document in Mongo using just the _id? I believe the answer is "no", but I'm curious to know if there is a method that allows for this. Target a document by _id (single document). If the readAt field exists on ...

How can I utilize React hook to choose multiple items?

I am currently working on developing a next js application. As part of this project, I have been tasked with creating a custom dropdown select menu using react hooks, specifically useState. The code I have written for this is as follows. Data- export defa ...

Update the navigation bar from displaying "LOGIN" to "LOGOUT

I am facing a challenge in updating the navbar login link to a logout link once the user logs in. I have attempted the following: header.ejs: <ul class="nav navbar-nav navbar-right"> <li id="home"><a href="/ ...

Highlighting the content within Material-UI's <Dialog> using ReactJS without affecting the entire webpage

I have an issue in my ReactJS project with the <Dialog> component from Material-UI (http://www.material-ui.com/#/components/dialog). When I open the <Dialog> and press command + a on my Mac, it highlights the entire page instead of just the con ...

Run ajax function prior to changing location; status now marked as canceled

Imagine needing to redirect a page when a button is clicked: <div onClick="clickButton"></div> function clickButton(href) { // an HTTP post request is sent here, without a callback or then/done function sendSomeRequest() location.href ...

Troubleshooting Problems with POST Requests in ExpressJS

Currently, I am working on developing a feature in NodeJS that allows users to upload files. However, I am encountering difficulties while attempting to make a simple POST request. In my index.ejs file, I have written code that generates a form and initia ...

JSON Eval function encountered an identifier that was not anticipated

Here is a code snippet that I found for rating a page. It works perfectly on my local machine, but once I upload it to the server, it throws a syntax error. function rtgAjax(elm, ratev) { var cerere_http = get_XmlHttp(); // get XMLHttpRequest object ...

Utilizing the .fadeToggle() function to create a fading effect for text, which fades in and out

I am on the verge of achieving my goal, but I could use a little more assistance with this. $('.change').hover(function() { $(this).fadeToggle('slow', 'linear', function() { $(this).text('wanna be CodeNinja' ...

Navigating through object keys in YupTrying to iterate through the keys of an

Looking for the best approach to iterate through dynamically created forms using Yup? In my application, users can add an infinite number of small forms that only ask for a client's name (required), surname, and age. I have used Formik to create them ...

Tips on showcasing a nested array in Next.js or converting it into an object

{ "count": 2, "rows": [ { "id": "5ab46e31-391c-46a7-8e45-db9ada07626d", "name": "admin", "email": "<a href="/cdn-cgi/l/email-p ...

There was an error caught: the object is not a function, specifically the button inside a form

Here is a snippet of code from my jsp page: <form name="programarRutasForm" method="post" action="/SGT_Galp_web/programarRutas.do"> <table> <tr> <td> <input type="button" name="insereVuelta" ...

File not found: The specified file 'C:Self Project eact-shopper eact-shopperclientuildindex.html' does not exist

I followed the tutorial and startup code by Reed Barger exactly, but every time I try to run the server I encounter this error: Error: ENOENT: no such file or directory, stat 'C:\Self Project\react-shopper\react-shopper\client&bso ...

The proper usage of middleware in vue-router

I've set up routes in Vue and added some middleware conditions before each route, but it's not functioning as expected. Below is the content of my router/index.js file: const token = computed(() => useAuthStore().token); // Main Router cons ...

an explanation of the date format used in Google Calendar

I'm attempting to incorporate Google Calendar into my website using the following URL: <a href="https://calendar.google.com/calendar/render? action=TEMPLATE& text={{ticket.subject}}& dates=20170127T210000Z/20170127T220000Z& ...