By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
How to set the dropdown value by clicking on a table row
Javascript – How to set the dropdown value by clicking on a table row
JavaScript
Attempting to increase the counter, when the object's tag exist
Javascript – Attempting to increase the counter, when the object’s tag exist
JavaScript
Cycle2 JS center active slide
Javascript – Cycle2 JS center active slide
JavaScript
Can import all THREE.js post processing modules as ES6 modules except OutputPass
Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass
JavaScript
How to return closest match for an array in Google Sheets Appscript
Javascript – How to return closest match for an array in Google Sheets Appscript
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > JavaScript > Javascript – How to draw a dual line chart where one line is straight
JavaScript

Javascript – How to draw a dual line chart where one line is straight

Admin
Last updated: 2023/12/09 at 7:30 PM
Admin
Share
3 Min Read
How to draw a dual line chart where one line is straight

Problem:

I want to make a chart that looks like the image belowenter image description here

Contents
Problem:Solution:

Now the problem is, I only have the start and end value of “Ideal Tasks Remaining”, start value is 2000 and end value 0. I have all the values for “Actual Tasks Remaining”. Is this kind of visualization possible in apex-chart or any chart for that matter? Thank you

I have tried giving just the start and end value but that line is not visible. Other line shows just fine.

Solution:

Maybe this will help. If you know the start and end values of y for the “Ideal Tasks Remaining” then you can calculate the slope of that line and its y values at each x point in your data. You can then feed this into the chart. Here is an example:

// Sample data
let days = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let sums = [2000, 2557, 1146, 1833, 990, 1250, 268, 700, 800, 90, 0]

// When x is 0, y is 2000
let x1 = 0 //
let y1 = 2000

// At the last point of the data, y is 0 <-- Assumed from the example chart posted
let x2 = days.slice(-1)
let y2 = 0

// Calcuate the slope of the Ideal Tasks Remaining line
let slope = (y2 - y1) / (x2 - x1)

// Calculate the y values of Ideal Tasks Remaining at each x
let trend = days.map((x) => slope * x + y1)

// Make the chart
let options = {
  chart: { type: 'line' },
  markers: {
    size: 5
  },
  series: [
    {
      name: 'Actual Tasks Remaining',
      data: sums
    },
    { name: 'Ideal Tasks Remaining', data: trend }
  ],
  xaxis: {
    categories: days,
    title: {
      text: 'Itiration Timeline (days)'
    }
  },
  yaxis: {
    title: {
      text: 'Sum of Task Estimates (days)'
    }
  }
}

let chart = new ApexCharts(document.querySelector('#chart'), options)

chart.render()
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<div id="chart"></div>

Expand snippet

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article I can't get the value of input field Javascript – I can’t get the value of input field
Next Article React - How to make input cursor stay before % symbol? Javascript – React – How to make input cursor stay before % symbol?
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -

You Might Also Like

How to set the dropdown value by clicking on a table row

Javascript – How to set the dropdown value by clicking on a table row

February 11, 2024
Attempting to increase the counter, when the object's tag exist

Javascript – Attempting to increase the counter, when the object’s tag exist

February 11, 2024
Cycle2 JS center active slide

Javascript – Cycle2 JS center active slide

February 10, 2024
Can import all THREE.js post processing modules as ES6 modules except OutputPass

Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass

February 10, 2024
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?