JSON dataset for advanced charting with ApexCharts

I am encountering difficulties in displaying data from a JSON in my apexchart series.

Below is an example of my chart with the desired JSON data that I am struggling to write.

var _seed = 42;
Math.random = function() {
    _seed = _seed * 16807 % 2147483647;
    return (_seed - 1) / 2147483646;
};

var options = {
    series: [{
        name: "Q",
        data: [0, 4800, 9500, null],
    },
    {
        name: "Q - 1",
        data: [0, 6500, 12000, 16000]
    },{

        name: "Q Target",
        data: [15500, 15500, 15500, 15500]

    },

    ],
    chart: {
      height: 350,
      type: 'line',
      zoom: {
        enabled: false
      }
    },
    dataLabels: {
      enabled: false
    },
    stroke: {
      curve: 'straight'
    },
    title: {
      text: 'Clicks',
      align: 'left'
    },
    grid: {
      row: {
        colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
        opacity: 0.5
      },
    },
    xaxis: {
      categories: [' ', 'Month1', 'Month2', 'Month3'],
    }
};

var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
#chart {
    max-width: 450px;
    margin: 35px auto;
}
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill"></script>
<script src="https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>

<div id="chart"></div>

If anyone has any insights or suggestions, they would be greatly appreciated.

Answer №1

Here is the JSON representation used to extract data for the apexchart

 {
    "data_clicks":[
        {
            "name":"Q",
            "data":[
                {
                    "x":" ",
                    "y":0
                },
                {
                    "x":"Month1",
                    "y":2400
                },
                {
                    "x":"Month2",
                    "y":5200
                },
                {
                    "x":"Month3",
                    "y":null
                }
            ]
        },
        {
            "name":"Q - 1",
            "data":[
                {
                    "x":" ",
                    "y":0
                },
                {
                    "x":"Month1",
                    "y":1800
                },
                {
                    "x":"Month2",
                    "y":7150
                },
                {
                    "x":"Month3",
                    "y":10200
                }
            ]
        },
        {
            "name":"Q Target",
            "data":[
                {
                    "x":" ",
                    "y":11000
                },
                {
                    "x":"Month1",
                    "y":11000
                },
                {
                    "x":"Month2",
                    "y":11000
                },
                {
                    "x":"Month3",
                    "y":11000
                }
            ]
        }

    ],
    

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

The clarity of an HTML input field is still unclear despite attempting to clear it using the clear()

When I created a form in HTML using PHP, AJAX, JavaScript, and jQuery, I encountered an issue where after entering data and updating it in the database, the input fields were not being cleared. I tried using clear() in JavaScript but it didn't work. C ...

The functionality of Ajax is limited when it comes to handling multiple div elements at the same

Seemingly silly question ahead, but I've been grappling with it for days to no avail. If anyone can help me solve this, please state your price and provide your PayPal details – the money is yours :). What I'm trying to achieve is to add a "Add ...

By changing the name of my file to .js.erb, I am able to seamlessly incorporate erb syntax within my javascript code, but this

Currently, I am using chessboard-0.3.0.js in a rails application. Due to the rails asset pipeline setup, I've had to make adjustments to the js code specifically related to rendering images, such as Pieces. In line 445 of chessboard.js, it states: c ...

All the details from this run are available in the npm run dev log on Ubuntu

Good day! I've been working on deploying a page built in vue.js, and after uploading all the files successfully, I encountered an issue when trying to run "npm run dev." No matter what I try, including re-installing npm dependencies and starting from ...

Add various inputs to a table using JavaScript

I came across a situation where I needed to append lines into a table in a specific way. However, I encountered an issue with JavaScript not accepting any input type='text' for an unknown reason. When I used a normal text variable, it worked fine ...

Are MVC Controllers fundamental components in a Node.js application, or just another piece of the puzzle?

Currently, I am in the process of developing a web crawler using Node. This project aims to crawl through my different bank accounts and generate a quick summary of my financial situation. Although I am fully aware of the security concerns involved in this ...

What could be causing the unexpected token error when sending an http post request in AngularJS?

When trying to perform an HTTP post request, I was able to successfully achieve it using the following command: curl --request POST --url https://api.sendgrid.com/v3/mail/send --header 'Authorization: Bearer xxxxxxxxxxxxx' --header 'Content ...

When attempting to modify an object that was initialized outside of a function, I am unable to change its value, or sometimes the function may not run at all. This

Currently in the process of constructing a social network utilizing nodejs, my knowledge on the subject matter is quite novice. This marks my initial discourse on the topic, and I would greatly appreciate your comprehension. Within my social network frame ...

Tips for ensuring sequential execution of $.post requests without ajax alternative

Can I make synchronous requests with $.post in this code snippet? function loadTest() { var questionIDs = []; var count = 0; console.log("getting test"); $.post("db.php", function(data) { obj = jQuery.parseJSON(data); var questionCount = obj.l ...

Using JMeter's Json Extractor to Parse Data from Multiple HTTP Requests

After configuring a ForEach Controller to run several HTTP requests, my goal is to extract JSON values from the response bodies of each request. However, when attempting to use a JSON Extractor PostProcessor on the HTTP Request, I am only able to retriev ...

What is the best way to handle the return value from using indexOf on a string?

I am looking to manipulate the value returned by a specific conditional statement. {{#each maindata-hold.[2].qa}} <div class="section"> <a href="javascript:void(0)" class="person-link" id="{{id}}"> <span class="name- ...

Display information upon the clicking of a button and update the color of the selected button

When a button is pressed, I want to display content and change the color of the active button. Currently, I can do each operation individually, but I'm struggling to merge these functionalities. This is how my script looks like for displaying the con ...

Choose the initial full text that corresponds with a portion of the text

I am currently working on a page with multiple <string> tags containing different strings, like 'Is this a String?  Yes'. My goal is to use JQuery to locate the first instance of 'Is this a String?  ' and extract either ...

Switching between different sections of a webpage

Seeking assistance with implementing a transition effect between sections on a single-page application. All sections are located on the same page, but only one section is displayed at a time. When an event occurs, the display property of the requested sect ...

Detecting collisions in three.js – a comprehensive guide

Currently, I am working with three.js and have incorporated two mesh geometries into my scene. I am looking for a way to detect collisions if these geometries intersect or would intersect when translated. How can I carry out collision detection using thre ...

Implementation of multiple angular guards causing a crash on the page

I have been attempting to implement separate guards for distinct pages. Essentially, I am checking a boolean parameter to determine if a user is logged in or not. Below are the two guard.ts codes that I am using: export class IsAuthenticatedGuard implemen ...

Legend click functionality works well in hiding the bars, but unfortunately, the data values in the charts.js are not being concealed as expected

When I click on the legend, the bar is hidden in the charts.js bar chart. However, the data value associated with the bar is not hidden. I have provided a link to the JS Fiddle code below: Check out the JS Fiddle here: https://jsfiddle.net/npyvw1L8/ var ...

A guide on implementing multiline properties in a property file for Selenium WebDriver

At the moment, I am focusing on utilizing Selenium WebDriver with code that is developed in Java. In the snippet below, I have successfully verified if the dropdown values match the UI for one dropdown. Now, I aim to extend this capability to check multip ...

JavaScript: A dynamic table is created with columns populated by JSON data. The row structure is compromised

On my webpage, I pull in two sets of JSON data: 1) warehouses and 2) items. After receiving an Ajax search response from my view, I need to dynamically generate the TDs of a table based on the warehouses information. The goal is to populate all TDs for ev ...

Issue with the JSON response in MVC 4

I have been struggling to bind JSON values to specific text boxes. It works with dynamically created textboxes but not with static ones that are already present. I've been stuck on this issue for 2 days and despite searching the internet, I couldn&apo ...