Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring Options in Tw-Elements Charts #2350

Open
memiljamel opened this issue Oct 19, 2024 · 1 comment
Open

Configuring Options in Tw-Elements Charts #2350

memiljamel opened this issue Oct 19, 2024 · 1 comment

Comments

@memiljamel
Copy link

Hello,

I am using the charts component from Tw-Elements and have found a way to initialize the chart using data attributes. Below is an example of the HTML code I am using:

<div class="mx-auto w-11/12 overflow-hidden md:w-3/5">
  <canvas
    data-twe-chart="line"
    data-twe-dataset-label="Traffic"
    data-twe-labels="['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']"
    data-twe-dataset-data="[2112, 2343, 2545, 3423, 2365, 1985, 987]">
  </canvas>
</div>

For chart initialization, I am using:

import {
  Chart,
  initTWE,
} from "tw-elements/js/chart.es.min.js";

initTWE({ Chart });

However, I would like to know how to configure options, such as disabling the legend display with legend.display = false.

Is there a way to set these options using data attributes, or do I need to configure the options through JavaScript after initialization? If so, could you please provide an example of how to do that?

Thank you for your help!

@iprzybysz
Copy link
Contributor

Hi @memiljamel , there is no data attribute available for this option. You need to configure it through JavaScript. Configure options object like below to disable the legend display:

const options = {
  plugins: {
    legend: {
      display: false,
    },
  },
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants