Exploring the world of HighCharts

I am trying to use Highcharts to calculate and visualize the magnitude of a complex number. Currently, my code is displaying the real and imaginary values separately on the graph. However, I seem to be facing issues with the "For loop" that I implemented. As a newcomer to Highcharts, I would appreciate it if someone could point out where I may have gone wrong?

<!DOCTYPE html>
    <html>
    <head>
        <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
        <script src="http://code.highcharts.com/highcharts.js"></script>
        <script src="http://code.highcharts.com/modules/exporting.js"></script>

    </head>
    <body>

    <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
    <script>

        function makeChart(){

            $('#container').highcharts({


                title: {
                    text: '',
                    x: -20 //center
                },
                subtitle: {
                    text: '',
                    x: -20
                },
                xAxis: {
                    type: ''
                },
                yAxis: {
                    title: {
                        text: ''
                    },

                },
                legend: {
                    enabled: false,
                },
                series: [{
                    "name": "rawDataFreq",
                    "data": [0.005,
                        0.01,
                        0.015,
                        0.02,
                        0.024999999,
                        0.029999998,
                        0.035,
                        0.04,
                        0.045,
                        0.049999997,
                        0.054999995,
                        0.06,
                        0.065,
                        0.07,
                        0.075,
                        0.08,
                        0.085,
                        0.09,
                        0.095,
                        0.1,
                        0.105,
                        0.11,
                        0.115,
                        0.12,
                        0.125,
                        0.13,
                        0.13499999,
                        0.13999999,
                        0.145,
                        0.14999999,
                        0.15499999,
                        0.16,
                        0.16499999,
                        0.16999999,
                        0.175,
                        0.17999999,
                        0.18499999,
                        0.19,
                        0.195,
                        0.19999999,
                        0.20499998]
                }, {
                    "name": "rawDataReal",
                    "data": [0.0201808685573576,
                        0.0767697223756945,
                        0.158682648165923,
                        0.249837894338925,
                        0.332117497531074,
                        0.388486758487953,
                        0.405658247813341,
                        0.375893015564664,
                        0.297781091351485,
                        0.176066765803544,
                        0.0207198248638412,
                        -0.154486149201635,
                        -0.333632455792532,
                        -0.50034171901689,
                        -0.639326270705166,
                        -0.73769508266917,
                        -0.78595341067365,
                        -0.778665026494336,
                        -0.714772534308723,
                        -0.597587985327756,
                        -0.434481612563418,
                        -0.236305675925078,
                        -0.0166000654885318,
                        0.209367793245636,
                        0.425668306470451,
                        0.616818629518453,
                        0.768867682979019,
                        0.870392411592417,
                        0.913338195367741,
                        0.893650069853281,
                        0.811642807549262,
                        0.672076423910065,
                        0.483922946878543,
                        0.259820779969512,
                        0.015255193586922,
                        -0.23249535939003,
                        -0.465581710361413,
                        -0.666874686000139,
                        -0.821246389838196,
                        -0.91674068380029,
                        -0.94553784066234]
                }, {
                    "name": "rawDataImag",
                    "data": [0.0675545914177537,
                        0.117156377483156,
                        0.134184248961863,
                        0.109954668889497,
                        0.0430934390486774,
                        -0.0604922824628415,
                        -0.188868821726251,
                        -0.32615740460395,
                        -0.454964125730713,
                        -0.558727284498096,
                        -0.623674108742807,
                        -0.640215131053008,
                        -0.603726043334295,
                        -0.514749853472742,
                        -0.378702137106123,
                        -0.205185549905176,
                        -0.00702389181498738,
                        0.200878821925561,
                        0.402758663360984,
                        0.583207037132255,
                        0.728307795918874,
                        0.826634253007817,
                        0.870054851853836,
                        0.854307437716744,
                        0.779313360666507,
                        0.649215214597493,
                        0.472135336231634,
                        0.2596646296396,
                        0.0261122004577115,
                        -0.212445675964786,
                        -0.439266519954881,
                        -0.638109861272021,
                        -0.794408318676894,
                        -0.896357162635668,
                        -0.935831163700915,
                        -0.909067785047298,
                        -0.817049526245347,
                        -0.665548148633306,
                        -0.464818102478558,
                        -0.228945676059982,
                        0.0251035652398094]


                }]



            })

            var result = 0;
            var resultArray = new Array ();
            var x = 0;
            var y=0;
            for (i=0; i < rawDataFreq.length; i++)
            {
                result = 0;
                x=rawDataReal[i];
                y=rawDataImag[i];
                result = (Math.sqrt(Math.pow(x,2)+Math.pow(y,2)));
                resultArray[i] = result;
            }

        }

        $(window).load(makeChart);


    </script>

    </body>
    </html>

Answer №1

rawDataFreq is missing from your for loop.
It's recommended to save the raw data in a variable first, then use it in series.dataname and in the for loop.

function createChart(){
    var myRawData = [/* your data array */];

    $('#container').highcharts({
        /* code truncated */
        series: [{
            "name": "myRawData",
            "data": myRawData
        }]
        /* code truncated */
    });

    for (var x = 0; x < myRawData.length; x++) {
        /* code truncated */
    }
}

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

Error 414: The URL exceeds the maximum length and cannot be processed

I am currently utilizing vuejs and sending an axios request to the server in order to download a csv file. download() { var that = this //this.records = [{id: 1, name: 'Jack'}, {id: 2, name: 'Jacky'}, {id: 3, name: &apos ...

Learn how to successfully carry on with event.preventdefault in JavaScript

Is there a way to create a modal that prompts the user to confirm if they want to leave the page without committing changes? These changes are not made within a <form> element, but rather on a specific object. I've attempted to use both $route ...

An issue with the Babel version is preventing the Express API from starting up successfully

Error! Message: [nodemon] starting `babel-node index.js` C:\Users\Zara Gunner\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-ma ...

Upon opening index.html in the browser, the jQuery code fails to execute, as no errors are displayed in the console

I am struggling to make a simple toggleClass() function work in jQuery and I can't seem to figure out why. This is just a beginner exercise for me with jQuery. The code works perfectly when I test it as a snippet or manually in the console, but when I ...

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 ...

Iterate over an array utilizing the $.getJSON method for data retrieval

I have encountered an issue while using a for loop to iterate through an array of dates in a JSON request. The problem is that the loop seems to be fetching only the first item in the array each time it iterates, as if ignoring the variable i or being cach ...

How to Retrieve OnLoad HTML/DOM Content for an HTML Page using PHP

I am interested in retrieving the initial HTML content of a web page specified by its URI. Ignoring error handling and assuming the HTML is static, here is a simple function: function GetDisplayedHTML($uri) { return file_get_contents($uri); } For stat ...

The Next.js build version encounters an issue with 'auth' property being undefined and causes a failure

Our team has been happily working on a Next.js based website for the past few months. Everything was running smoothly without any major issues until yesterday when we encountered an error on the production version while using router.push: Cannot read prope ...

Activate or deactivate a button depending on the input value of a TextField in React.js

I am currently designing a form similar to the one displayed in this image. I want the "Add" button to become active as soon as the user starts typing in the "Tags" input field. For this project, I am using material-ui and I have created an Input compone ...

PLupload does not support Flash runtime in Internet Explorer 8

I am facing a dilemma with a basic JavaScript function placed within the $(function() { ... }); block. var uploader = new plupload.Uploader({ runtimes: 'html5,flash,silverlight', browse_button: 'pickfiles', c ...

Tips for displaying a table with a button click

I am struggling to figure out how to embed a table inside a button in order to display the table when the button is clicked and hide it when clicked again. Below is the code I have been working with: function toggleTable(){ document.getElementById ...

The results generated by the Google Maps API are consistently consistent

const request = require('request'); var geocodeAddress = (location) => { var encodedLocation = encodeURIComponent(location); request({ url: `http://www.mapquestapi.com/geocoding/v1/address?key=APIKey&location=${encodedLocation}` ...

Is it possible to include more than one ng-app directive on a single HTML page in AngularJS?

When working with Angular JS, I've noticed that I only get the desired output if I remove either the ng-app directive for demo1 or the models. It seems like having two ng-app directives active at the same time causes issues. As a beginner in Angular J ...

Is it possible to retrieve data from a database using jQuery and store it in separate variables?

I am able to print out one field from a table, but I want to display all fields in separate tables. How can I achieve this? Below is my save/load code: // Save/Load data. $('').ready(function() { if($.cookie('code')) { $.aj ...

Combining two numbers retrieved from Firebase using React

Hello, I am new to React and finding it challenging to perform mathematical calculations with React. I have been attempting to add two values retrieved from a Firebase database, but they keep displaying as strings without adding the actual values together. ...

Is it possible to modify a dependency import based on the specific request?

How can I switch between test mode and live mode using Stripe's SDK based on a query parameter in my internal form service for collecting payments? For example, consider this route: router.post("/:formId", function(req, res, next) { let isTest ...

Output various strings to the standard output and stream them individually

Is there a way to redirect each string output to standard out to another command? // Example file: example.js #!/usr/bin/env node process.stdout.write('foo') process.stdout.write('bar') After running ./example.js | wc -m, the total ch ...

How can labels be added when mapping over JSON data?

If I have JSON data structured like this: { "siteCode": "S01", "modelCode": "M001", "modelDesc": "Desc01", "price": 100 "status": "A", "startDate": "Ma ...

How can I delay the loading of a link until the pop-up is closed?

I have successfully implemented a pop-up on my website, but I am facing an issue where I need to prevent any linked pages from loading until the visitor clicks on the accept button. However, I am struggling to make it function as intended. Below is the sn ...

Using Material-UI to implement a Link component from the react-router library

I'm having trouble integrating the <Link/> component into my material-ui AppBar. Here is my navigation class: class Navigation extends Component { constructor(props) { super(props) } render() { var styles = { appBar: { ...