Tips for Generating Box Plot Diagram with ASP.NET, C# or JavaScript

Can someone provide guidance on how to create a Box Plot Chart using ASP.net, C#, or JavaScript?

I came across this code online but I'm not sure how to implement it for my specific case:

Code:

List<String> xValue = new List<String> { "Ala (A)", "Arg (R)", "Asn (N)", "Asp (D)", "Cys (C)", "Gln (Q)", "Glu (E)", "Gly (G)", "His (H)", "Ile (I)", "Leu (L)", "Lys (K)", "Met (M)", "Phe (F)", "Pro (P)", "Ser (S)", "Thr (T)", "Trp (W)", "Tyr (Y)", "Val (V)", "Pyl (O)", "Sec (U)" };
    Chart Chart = new Chart();
    Chart.chart_main.Series.Clear();
    Chart.chart_main.Series.Add("BoxPlotSeries");
    for (Int32 i = 0; i < xValue.Count; i++)
    {
        Chart.chart_main.Series.Add(xValue[i]); 
    }

    for (Int32 i = 0; i < DYL; i++)
    {
        if (Data[i, 0] == null) break;
        // Loop through data and add points
    }

    Chart settings...

Please assist me with this, thank you!

Answer №1

Here is an illustration of an ASP.NET sample:

    <asp:Chart ID="Chart1" runat="server" Width="600px">
        <Series>
            <asp:Series Name="Series1" ChartType="BoxPlot" YValuesPerPoint="6">
                <Points>
                    <asp:DataPoint XValue="1" YValues="10,60,20,50,30,40" />
                    <asp:DataPoint XValue="2" YValues="40,90,50,80,60,70" />
                    <asp:DataPoint XValue="3" YValues="20,70,30,60,40,50" />
                </Points>
            </asp:Series>
        </Series>
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1">
                <AxisY>
                    <MajorGrid LineColor="DarkGray" LineDashStyle="Dot" />
                    <MajorTickMark LineColor="DarkGray" LineDashStyle="Dot" />
                </AxisY>
                <AxisX>
                    <MajorGrid LineColor="DarkGray" LineDashStyle="Dot" />
                    <MajorTickMark LineColor="DarkGray" LineDashStyle="Dot" />
                </AxisX>
            </asp:ChartArea>
        </ChartAreas>
    </asp:Chart>

https://i.sstatic.net/yTmpl.png

To find more information about this presentation, please visit: MSDN - Box Plot Chart

UPDATE: You have the option to dynamically bind data as seen below:

    protected void Page_Load(object sender, EventArgs e)
    {
        MyDataCollection data = new MyDataCollection();
        Chart1.Series[0].Points.DataBind(data, "XValue", "LowWhisker,UpWhisker,LowWBox,UpBox,Average,Median", null);
    }

public class MyDataCollection : List<MyData>
{
    public MyDataCollection()
    {
        Add(new MyData { XValue = 1, LowWhisker = 10, UpWhisker = 60, LowWBox = 20, UpBox = 50, Average = 30, Median = 40 });
        Add(new MyData { XValue = 2, LowWhisker = 40, UpWhisker = 90, LowWBox = 50, UpBox = 80, Average = 60, Median = 70 });
        Add(new MyData { XValue = 3, LowWhisker = 20, UpWhisker = 70, LowWBox = 30, UpBox = 60, Average = 40, Median = 50 });
    }
}

public class MyData
{
    public double XValue { get; set; }
    public double LowWhisker { get; set; }
    public double UpWhisker { get; set; }
    public double LowWBox { get; set; }
    public double UpBox { get; set; }
    public double Average { get; set; }
    public double Median { get; set; }
}

Remember to call DataBind() when adding or removing data from your collection.

UPDATE 2: You can change XValue to a string by adjusting MyData and MyDataCollection accordingly:

https://i.sstatic.net/ljrKf.png

UPDATE 3: Using a DataTable,

    protected void Page_Load(object sender, EventArgs e)
    {
        MyDataTable dt = new MyDataTable();

        foreach (DataRow row in dt.Rows)
            Chart1.Series[0].Points.AddXY(row["Status"], new object[] { row["Min"], row["Max"], row["Avg"], row["Percentile25"], row["Percentile50"], row["Percentile75"] });
    }

public class MyDataTable : DataTable
{
    public MyDataTable()
    {
        Columns.Add("Title", typeof(string));
        Columns.Add("Status", typeof(string));
        Columns.Add("Min", typeof(double));
        Columns.Add("Max", typeof(double));
        Columns.Add("Avg", typeof(double));
        Columns.Add("Percentile25", typeof(double));
        Columns.Add("Percentile50", typeof(double));
        Columns.Add("Percentile75", typeof(double));

        DataRow row = NewRow();
        row["Status"] = "Status 1";
        row["Min"] = 10;
        row["Max"] = 60;
        row["Avg"] = 20;
        row["Percentile25"] = 50;
        row["Percentile50"] = 30;
        row["Percentile75"] = 40;
        Rows.Add(row);

        row = NewRow();
        row["Status"] = "Status 2";
        row["Min"] = 40;
        row["Max"] = 90;
        row["Avg"] = 50;
        row["Percentile25"] = 80;
        row["Percentile50"] = 60;
        row["Percentile75"] = 70;
        Rows.Add(row);

        row = NewRow();
        row["Status"] = "Status 3";
        row["Min"] = 20;
        row["Max"] = 70;
        row["Avg"] = 30;
        row["Percentile25"] = 60;
        row["Percentile50"] = 40;
        row["Percentile75"] = 50;
        Rows.Add(row);
    }
}

https://i.sstatic.net/pRCm5.png

Answer №2

There seems to be a mistake in the 3rd example, Edit 3 Using a DataTable. The issue lies in the sequence of the statistical values that are being inserted into the object array.

I propose that the statement should follow a structure similar to Edit 1 & Edit 2 examples, instead of the current implementation.

It might be more appropriate to write it as: Chart1.Series[0].Points.AddXY(row["Status"], new object[] { row["Min"], row["Max"], row["Percentile25"], row["Percentile75"], row["Avg"], row["Percentile50"]});

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

What could be the reason for PhantomJS getting stuck when jQuery is invoked?

Currently, I am using PhantomJS 2.0.0 on a Mac OS X Yosemite: $ phantomjs --version 2.0.0 The script I have attached below seems to get stuck at the line where it calls $('h1').size(): system = require('system'); function usage() { ...

What is the best way to create a TypeScript function similar to a 'map' in React?

I recently started learning TS and am having trouble typing this arrow function: const mapLikeGet = (obj, key) => { if (Object.prototype.hasOwnProperty.call(obj, key)) return obj[key] } ...

Query regarding timing in JavaScript

I recently started learning JavaScript and I am facing a challenge with running a check to determine if it is daylight. Currently, I am using Yahoo's weather API to retrieve information about sunrise and sunset times. The issue I have encountered is h ...

Guide to sending a binary body in a POST request using Meteor.js

I've been struggling with a challenging issue in Meteor.js that I'm hoping to resolve. My goal is to make API calls to a face detection open API service by sending an image and receiving a JSON object in return. However, I have hit a roadblock as ...

Failure of app script to retrieve data from an external spreadsheet

In an attempt to consolidate data, this program aims to transfer information from one spreadsheet to another. The process involves retrieving all files within a designated folder (all of which are spreadsheets), extracting values from a specific range, and ...

What is the best way to retrieve ember model relation properties within routes and controllers?

Currently using ember 2.7.0, I am facing an issue while setting up my ember app with a currentUser.organization derived from the authenticated token. Although I can successfully resolve the currentUser, I am encountering difficulties in resolving the prope ...

What is the best way to implement multilanguage support in nodejs without relying on cookies or external modules?

Currently, I am in the process of transitioning all my projects to node.js in order to enhance my JavaScript skills. Using Node.js along with the Express module, one of my clients who runs a translation company has requested that I incorporate two language ...

Is it a Mozilla Firefox glitch or something else?

After writing the code, I noticed a bug in Firefox and a small bug in Chrome. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ...

Execute a function on each item within a JavaScript array

I'm working with a JavaScript array and trying to figure out how to display each item in the array within an h1 element. Can anyone help me out? This is what I have come up with so far: names = ["Jeff", "Steve", "Bill"]; function show() { let c ...

The process of altering a property in input data within Vue.js

I have a component called Input.vue that displays a label and an input field of some type. Here is how it looks: <template> <div class="form-element"> <label :for="inputId" :class="['form-element-tit ...

Guidance on targeting specific coordinates on a webpage with a single click

While working with Selenium Webdriver, I encountered a situation where I needed to click on a link within a page. However, I was unable to access the element using the href value as shown below: var link = WebDriver.FindElements(By.XPath("//a[@href=' ...

Perform a jQuery function and SQL query when a selection is made in a dropdown menu

Struggling to execute a SQL query on drop-down menu selection. Here's my current code: <script> $('#templateid').change(function(DoUpdateOnSelect) { $.post('page.edit.php?page_id=(-->Need help in retrieving this id from the pa ...

Remove an item using a function embedded within it

I've been grappling with this issue for quite some time now and I'm unable to find a solution. My approach involves Vue(JS). What I'm attempting to achieve is to push notifications into an Object and then present them to the user. Each noti ...

Continuously iterate through a PHP page until the session variable reaches a specific value

I am in the process of creating a web-based exam. All questions and answers are stored in a MySQL database. I began by retrieving and displaying one question along with multiple-choice answers. I used a session variable $_SESSION['questionno'] = ...

Logging to the console using an If/Else statement, with the Else block containing code that

I'm encountering a peculiar issue with my If statement. I'm modifying the state (true/false) of an object based on onMouseEnter and onMouseLeave. I can execute the code when it's true, but if I include any code in the else statement, it ma ...

How can a tooltip be displayed on a disabled toggleButton?

When trying to display a tooltip for MUI's ToggleButton while it is disabled, I am encountering an issue where the tooltip works fine for enabled ToggleButtons but breaks for disabled ones. <ToggleButton value={item?.key} aria-label="left aligned" ...

The scope chain in Chrome v71 connects the anchor tag to the inner img tag

Ever since updating to Chrome v71, I've noticed a strange issue with the scope of an anchor tag that contains an img tag inside. Take a look at this snippet: <a href="#none" onclick="debugger;complete();"> <img src="https://clickmeuk.net/w ...

Can the front end acquire JSON data from a URL, save it as a JSON file with a unique name, and store it in a designated location?

I'm facing a straightforward problem with my React Native project. I am attempting to create a script that will be executed during the build process to fetch JSON data from a URL and then store it as a JSON file with a unique name in a specific direct ...

What steps can be taken to resolve the issue of the Cannot POST /index.html error?

Here is an example of a calculator app created using HTML and Javascript. Upon running the program with nodemon and accessing localhost:3000, pressing the submit button triggers an error on Google Chrome. [nodemon] starting `node calculator.js` Server sta ...

I am configuring Jest in my Vite and TypeScript-powered React project

I am having trouble with the relative path of the file I imported in App.test.tsx. It keeps showing me this error message: Cannot find module '@/components/items/card.tsx' from 'src/__tests__/App.test.tsx' Below is the code snippet: // ...