简体   繁体   English

如何确保每次从下拉列表中选择图表时都会加载图表?

[英]How can I ensure that my charts diagram load every time I choose it from my dropdown?

Hey guys I have built a dropdown menu that allows me to choose from different roles.嘿伙计们,我已经建立了一个下拉菜单,允许我从不同的角色中进行选择。 Every time I choose a role my line chart loads.每次我选择一个角色时,我的折线图都会加载。 When I choose another option it loads again.当我选择另一个选项时,它会再次加载。 However, when I choose the option that I have decided for again it does not load again.但是,当我再次选择我决定的选项时,它不会再次加载。 So it just loads once and then not anymore.所以它只加载一次,然后不再加载。 Do you have an idea of how I can solve it?您知道我该如何解决吗?

<select name="job-role" id="job-role" onchange="updateChartType()">
  <option value="" disabled selected hidden>Select a Job Role</option>
  <option value="backend">Backend Engineer</option>
  <option value="frontend">Frontend Engineer</option>
  <option value="mobile">Mobile Engineer</option>
  <option value="full">Full-stack Engineer</option>
  <option value="devops">DevOps & Infrastructure </option>
  <option value="security">Security Engineer</option>
  <option value="dataan">Data Analysis & BI</option>
  <option value="dataen">Data Engineer</option>
  <option value="datasci">Data Scientist</option>

</select>

<canvas id="jobChart"></canvas>



const ctx = document.getElementById('jobChart').getContext('2d')
const chart = new Chart(ctx, {
  type: 'line',
  data: {
    labels: ["1", "2", "3", "4", "5", "6", "7", "8", "9+"],
    datasets: []
  },
});

const jobDatasets = {
  
  
  backend: [{
    label: "25th Percentile",
    backgroundColor: '#c4c1ff',
    pointBackgroundColor: "645bff",
    borderColor: '#645bff',
    fill:false,
    pointRadius: 0,
    borderWidth:1,
    pointBorderWidth: 3,
    pointHoverRadius:3,
    lineTension: 0.3,
    pointHitRadius:3,
    data: [27, 36, 38, 46, 50, 54, 63, 65, 71, 77]
  }, {
    label: "10th - 90th Percentile",
    fill:false,
    borderColor: "#645bff",
    backgroundColor: "#645bff",
        pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    borderWidth: 1,
    lineTension: 0.3,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [39, 66, 62, 65, 71, 80, 82, 86, 99, 107]
  }, 
  {
    label: "Median",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#0d0e25",
        borderWidth: 1,
    pointRadius: 2,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    lineTension: 0.3,
    pointHitRadius: 3,
    data: [31, 39, 46, 51, 54, 61, 65, 70, 79, 85]
  },
  
  {
    label: "25th - 75th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#645bff",
    pointRadius: 0,
    lineTension: 0.1,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    borderCapStyle: 'butt',
    borderDash: [],
    borderDashOffset: 0.0,
    lineTension:0.3,
    borderJoinStyle: 'miter',
    data: [37, 50, 51, 55, 63, 69, 73, 80, 85, 94]
  },
  
  {
    label: "10th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    pointStyle: "circle",
    borderWidth: 1,
    lineWidth: 1,
    hoverRadius: 9,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    lineTension: 0.3,
    data: [24, 31, 35, 38, 46, 48, 52, 55, 59, 67]
  }] , 
  


  frontend: 
  [{ label: "25th Percentile",
    backgroundColor: '#c4c1ff',
    pointBackgroundColor: "645bff",
    borderColor: '#645bff',
    fill:false,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius:3,
    pointHitRadius:3,
    data: [40, 36, 38, 46, 50, 54, 63, 65, 71, 77]
  }, {
    label: "10th - 90th Percentile",
    fill:false,
    borderColor: "#645bff",
    backgroundColor: "#645bff",
        pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    borderWidth: 1,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [39, 66, 62, 65, 71, 80, 82, 86, 99, 107]
  }, 
  {
    label: "Median",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#0d0e25",
        borderWidth: 1,
    pointRadius: 2,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [31, 39, 46, 51, 54, 61, 65, 70, 79, 85]
  },
  
  {
    label: "25th - 75th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#645bff",
    pointRadius: 0,
    lineTension: 0.1,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    borderCapStyle: 'butt',
    borderDash: [],
    borderDashOffset: 0.0,
    borderJoinStyle: 'miter',
    data: [37, 50, 51, 55, 63, 69, 73, 80, 85, 94]
  },
  
  {
    label: "10th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    pointStyle: "circle",
    borderWidth: 1,
    lineWidth: 1,
    hoverRadius: 9,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    lineTension: 0.3,
    data: [24, 31, 35, 38, 46, 48, 52, 55, 59, 67]
  }] , 
  
  

   
  mobile: 
  [{ label: "25th Percentile",
    backgroundColor: '#c4c1ff',
    pointBackgroundColor: "645bff",
    borderColor: '#645bff',
    fill:false,
    pointRadius: 0,
    borderWidth:1,
    pointBorderWidth: 3,
    pointHoverRadius:3,
    pointHitRadius:3,
    data: [27, 36, 38, 46, 50, 54, 63, 65, 71, 77]
  }, {
    label: "10th - 90th Percentile",
    fill:false,
    borderColor: "#645bff",
    backgroundColor: "#645bff",
        pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    borderWidth: 1,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [39, 66, 62, 65, 71, 80, 82, 86, 99, 107]
  }, 
  {
    label: "Median",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#0d0e25",
        borderWidth: 1,
    pointRadius: 2,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [31, 39, 46, 51, 54, 61, 65, 70, 79, 85]
  },
  
  {
    label: "25th - 75th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#645bff",
    pointRadius: 0,
    lineTension: 0.1,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    borderCapStyle: 'butt',
    borderDash: [],
    borderDashOffset: 0.0,
    borderJoinStyle: 'miter',
    data: [37, 50, 51, 55, 63, 69, 73, 80, 85, 94]
  },
  
  {
    label: "10th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    pointStyle: "circle",
    borderWidth: 1,
    lineWidth: 1,
    hoverRadius: 9,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    lineTension: 0.3,
    data: [24, 31, 35, 38, 46, 48, 52, 55, 59, 67]
  }],
  
  
   
   
   
   
  full: 
  [{ label: "25th Percentile",
    backgroundColor: '#c4c1ff',
    pointBackgroundColor: "645bff",
    borderColor: '#645bff',
    fill:false,
    pointRadius: 0,
    borderWidth:1,
    pointBorderWidth: 3,
    pointHoverRadius:3,
    pointHitRadius:3,
    data: [27, 36, 38, 46, 50, 54, 63, 65, 71, 77]
  }, {
    label: "10th - 90th Percentile",
    fill:false,
    borderColor: "#645bff",
    backgroundColor: "#645bff",
        pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    borderWidth: 1,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [39, 66, 62, 65, 71, 80, 82, 86, 99, 107]
  }, 
  {
    label: "Median",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#0d0e25",
        borderWidth: 1,
    pointRadius: 2,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [31, 39, 46, 51, 54, 61, 65, 70, 79, 85]
  },
  
  {
    label: "25th - 75th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#645bff",
    pointRadius: 0,
    lineTension: 0.1,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    borderCapStyle: 'butt',
    borderDash: [],
    borderDashOffset: 0.0,
    borderJoinStyle: 'miter',
    data: [37, 50, 51, 55, 63, 69, 73, 80, 85, 94]
  },
  
  {
    label: "10th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    pointStyle: "circle",
    borderWidth: 1,
    lineWidth: 1,
    hoverRadius: 9,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    lineTension: 0.3,
    data: [24, 31, 35, 38, 46, 48, 52, 55, 59, 67]
  }],
  
    
    
    
    
    
  devops: 
  [{ label: "25th Percentile",
    backgroundColor: '#c4c1ff',
    pointBackgroundColor: "645bff",
    borderColor: '#645bff',
    fill:false,
    pointRadius: 0,
    borderWidth:1,
    pointBorderWidth: 3,
    pointHoverRadius:3,
    pointHitRadius:3,
    data: [27, 36, 38, 46, 50, 54, 63, 65, 71, 77]
  }, {
    label: "10th - 90th Percentile",
    fill:false,
    borderColor: "#645bff",
    backgroundColor: "#645bff",
        pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    borderWidth: 1,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [39, 66, 62, 65, 71, 80, 82, 86, 99, 107]
  }, 
  {
    label: "Median",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#0d0e25",
        borderWidth: 1,
    pointRadius: 2,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [31, 39, 46, 51, 54, 61, 65, 70, 79, 85]
  },
  
  {
    label: "25th - 75th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#645bff",
    pointRadius: 0,
    lineTension: 0.1,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    borderCapStyle: 'butt',
    borderDash: [],
    borderDashOffset: 0.0,
    borderJoinStyle: 'miter',
    data: [37, 50, 51, 55, 63, 69, 73, 80, 85, 94]
  },
  
  {
    label: "10th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    pointStyle: "circle",
    borderWidth: 1,
    lineWidth: 1,
    hoverRadius: 9,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    lineTension: 0.3,
    data: [24, 31, 35, 38, 46, 48, 52, 55, 59, 67]
  }],
  
  
  
  
  security: 
  [{ label: "25th Percentile",
    backgroundColor: '#c4c1ff',
    pointBackgroundColor: "645bff",
    borderColor: '#645bff',
    fill:false,
    pointRadius: 0,
    borderWidth:1,
    pointBorderWidth: 3,
    pointHoverRadius:3,
    pointHitRadius:3,
    data: [27, 36, 38, 46, 50, 54, 63, 65, 71, 77]
  }, {
    label: "10th - 90th Percentile",
    fill:false,
    borderColor: "#645bff",
    backgroundColor: "#645bff",
        pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    borderWidth: 1,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [39, 66, 62, 65, 71, 80, 82, 86, 99, 107]
  }, 
  {
    label: "Median",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#0d0e25",
        borderWidth: 1,
    pointRadius: 2,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [31, 39, 46, 51, 54, 61, 65, 70, 79, 85]
  },
  
  {
    label: "25th - 75th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#645bff",
    pointRadius: 0,
    lineTension: 0.1,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    borderCapStyle: 'butt',
    borderDash: [],
    borderDashOffset: 0.0,
    borderJoinStyle: 'miter',
    data: [37, 50, 51, 55, 63, 69, 73, 80, 85, 94]
  },
  
  {
    label: "10th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    pointStyle: "circle",
    borderWidth: 1,
    lineWidth: 1,
    hoverRadius: 9,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    lineTension: 0.3,
    data: [24, 31, 35, 38, 46, 48, 52, 55, 59, 67]
  }],
  
  
  
  
  
  
  
  dataan: 
  [{ label: "25th Percentile",
    backgroundColor: '#c4c1ff',
    pointBackgroundColor: "645bff",
    borderColor: '#645bff',
    fill:false,
    pointRadius: 0,
    borderWidth:1,
    pointBorderWidth: 3,
    pointHoverRadius:3,
    pointHitRadius:3,
    data: [27, 36, 38, 46, 50, 54, 63, 65, 71, 77]
  }, {
    label: "10th - 90th Percentile",
    fill:false,
    borderColor: "#645bff",
    backgroundColor: "#645bff",
        pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    borderWidth: 1,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [39, 66, 62, 65, 71, 80, 82, 86, 99, 107]
  }, 
  {
    label: "Median",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#0d0e25",
        borderWidth: 1,
    pointRadius: 2,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [31, 39, 46, 51, 54, 61, 65, 70, 79, 85]
  },
  
  {
    label: "25th - 75th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#645bff",
    pointRadius: 0,
    lineTension: 0.1,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    borderCapStyle: 'butt',
    borderDash: [],
    borderDashOffset: 0.0,
    borderJoinStyle: 'miter',
    data: [37, 50, 51, 55, 63, 69, 73, 80, 85, 94]
  },
  
  {
    label: "10th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    pointStyle: "circle",
    borderWidth: 1,
    lineWidth: 1,
    hoverRadius: 9,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    lineTension: 0.3,
    data: [24, 31, 35, 38, 46, 48, 52, 55, 59, 67]
  }],
  
  
  
  
  
  dataen: 
  [{ label: "25th Percentile",
    backgroundColor: '#c4c1ff',
    pointBackgroundColor: "645bff",
    borderColor: '#645bff',
    fill:false,
    pointRadius: 0,
    borderWidth:1,
    pointBorderWidth: 3,
    pointHoverRadius:3,
    pointHitRadius:3,
    data: [27, 36, 38, 46, 50, 54, 63, 65, 71, 77]
  }, {
    label: "10th - 90th Percentile",
    fill:false,
    borderColor: "#645bff",
    backgroundColor: "#645bff",
        pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    borderWidth: 1,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [39, 66, 62, 65, 71, 80, 82, 86, 99, 107]
  }, 
  {
    label: "Median",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#0d0e25",
        borderWidth: 1,
    pointRadius: 2,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [31, 39, 46, 51, 54, 61, 65, 70, 79, 85]
  },
  
  {
    label: "25th - 75th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#645bff",
    pointRadius: 0,
    lineTension: 0.1,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    borderCapStyle: 'butt',
    borderDash: [],
    borderDashOffset: 0.0,
    borderJoinStyle: 'miter',
    data: [37, 50, 51, 55, 63, 69, 73, 80, 85, 94]
  },
  
  {
    label: "10th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    pointStyle: "circle",
    borderWidth: 1,
    lineWidth: 1,
    hoverRadius: 9,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    lineTension: 0.3,
    data: [24, 31, 35, 38, 46, 48, 52, 55, 59, 67]
  }],
  
  
  
  
  
  
  datasci: 
  [{ label: "25th Percentile",
    backgroundColor: '#c4c1ff',
    pointBackgroundColor: "645bff",
    borderColor: '#645bff',
    fill:false,
    pointRadius: 0,
    borderWidth:1,
    pointBorderWidth: 3,
    pointHoverRadius:3,
    pointHitRadius:3,
    data: [27, 36, 38, 46, 50, 54, 63, 65, 71, 77]
  }, {
    label: "10th - 90th Percentile",
    fill:false,
    borderColor: "#645bff",
    backgroundColor: "#645bff",
        pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    borderWidth: 1,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [39, 66, 62, 65, 71, 80, 82, 86, 99, 107]
  }, 
  {
    label: "Median",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#0d0e25",
        borderWidth: 1,
    pointRadius: 2,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    data: [31, 39, 46, 51, 54, 61, 65, 70, 79, 85]
  },
  
  {
    label: "25th - 75th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#645bff",
    pointRadius: 0,
    lineTension: 0.1,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    borderCapStyle: 'butt',
    borderDash: [],
    borderDashOffset: 0.0,
    borderJoinStyle: 'miter',
    data: [37, 50, 51, 55, 63, 69, 73, 80, 85, 94]
  },
  
  {
    label: "10th Percentile",
    fill:false,
    borderColor: "#c4c1ff",
    backgroundColor: "#c4c1ff",
    pointBackgroundColor: "#c4c1ff",
    pointHoverBackgroundColor: "#c4c1ff",
    pointHoverBorderColor: "#c4c1ff",
    pointStyle: "circle",
    borderWidth: 1,
    lineWidth: 1,
    hoverRadius: 9,
    pointRadius: 0,
    pointBorderWidth: 3,
    pointHoverRadius: 3,
    pointHitRadius: 3,
    lineTension: 0.3,
    data: [24, 31, 35, 38, 46, 48, 52, 55, 59, 67]
  }],
  
  
 
 }
  

document.getElementById('job-role').addEventListener('change', function() {
  chart.data.datasets = jobDatasets[this.value]
  chart.update()
});

HTML Code: HTML 代码:

<div id="chartContainer">
  <canvas id="jobChart"></canvas>
</div>

JS CODE: JS代码:

document.getElementById('job-role').addEventListener('change', function() {
   $('#jobChart').remove();
   $('#chartContainer').append('<canvas id="jobChart"><canvas>');
   
   //Here you need to call generate the graph again then add the values to dataset.   

   chart.data.datasets = jobDatasets[this.value]
   chart.update()
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以做些什么来确保每次从下拉列表中选择图表时重新加载图表? - What can I do to ensure that my charts diagram reload every time I choose it from my dropdown? 每次从下拉列表中选择项目时,如何使图表动态化? - How can I make my charts dynamic every time I choose an item from my dropdown? 我如何确保在使用图表之前加载它们? - How do i ensure that i load my charts before i use them? 如何确保来自我的Rails服务器的请求是从我的Rails视图发送的? - How can I ensure that the request coming to my Rails server was sent from my Rails view? 如何在我的网页上每分钟从所选时区更新时间? - How can I update the time from chosen timezone every minute on my webpage? 每次我的 JavaScript 文件从其中提取代码时,如何使变量“刷新”自身? - How can I make a variable “refresh” itself every time my JavaScript file has code pulled from it? 如何确保我的函数一次只作用于一个元素? (重新发布更多细节) - How can I ensure that my function only acts on one element at a time? (Repost with more details) 如何减少javascripts的加载时间? - How can I reduce the load time of my javascripts? 如何使阵列每次运行都能选择不同的选择? - How can I make my array choose different choices each time it runs? 如何使用d3.js在图表中添加标签? - How can I add labels to my diagram with d3.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM