English 中文(简体)
如何在图.js中 h倒 cur子时增加线宽度?
原标题:How to increase the line width when hovering the cursor in chart.js?

我知道,我可以修改这条线的宽度及其各点,改名为<条码>。

But how to increase the width of the line and its points when hovering the mouse cursor over a line? I tried hoverBorderWidth: 2, hoverRadius: 2 as suggested in the docs but with no success.

我在“谷歌应用”试验,在“html”档案中添加这些内容:

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-autocolors"></script>
问题回答

你的法典几乎是正确的,但你却想加上图纸。 BorderWidth or hover Radius.

内容

<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels"></script>

传真

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels"></script>

<canvas id="myChart"></canvas>

JS

const ctx = document.getElementById( myChart ).getContext( 2d );

// Create the chart with the plugin and other options
const chart = new Chart(ctx, {
  type:  bar ,
  data: {
    labels: [ Label 1 ,  Label 2 ,  Label 3 ],
    datasets: [{
      label:  Data ,
      data: [10, 20, 30],
      backgroundColor:  rgba(0, 123, 255, 0.5) 
    }]
  },
  options: {
    plugins: {
      datalabels: {
        display: false // Hide the data labels by default
      }
    },
    responsive: true,
    maintainAspectRatio: false,
    hover: {
      onHover: handleHover // Call the handleHover function on hover
    }
  }
});

// Function to handle the hover effect
function handleHover(activeElements) {
  if (activeElements.length > 0) {
    const element = activeElements[0];
    
    // Increase border radius and width
    element._model.borderWidth += 2;
    element._model.borderRadius = 10;
    
    // Display the data labels
    chart.options.plugins.datalabels.display = true;
    
    chart.update();
  } else {
    // Reset styles and hide data labels when not hovering
    chart.data.datasets[0].data.forEach((_, index) => {
      const element = chart.getDatasetMeta(0).data[index];
      
      element._model.borderWidth = 0;
      element._model.borderRadius = 0;
    });
    
    chart.options.plugins.datalabels.display = false;
    
    chart.update();
  }
}

让我知道,这是否有助于我的朋友工作。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签