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

Chart.js 3.0 support #44

Closed
benmccann opened this issue May 20, 2021 · 8 comments
Closed

Chart.js 3.0 support #44

benmccann opened this issue May 20, 2021 · 8 comments

Comments

@benmccann
Copy link

Chart.js 3.0 is out now. It'd be great to see this plugin updated

@y-takey
Copy link
Owner

y-takey commented May 20, 2021

Hi @benmccann , Thank you for telling me about chart.js@3 🎉
I would like to update this plugin in the near future!

@jagdaleganesh
Copy link

Hi , I would like to use this plugin. How I can use with latest ChartJS version. I need to register the plugin first before use.
Please let me know how I can use the it with latest chartjs version.
In case this plugin is not yet updated, is there any workaround to use with latest chartjs version.

@y-takey , I am waiting for your reply.

Thanks,

@y-takey
Copy link
Owner

y-takey commented Aug 22, 2021

Hi @jagdaleganesh , thanks for the request :)
It is WIP now, so please wait a little more.

@y-takey
Copy link
Owner

y-takey commented Aug 30, 2021

published chartjs-plugin-stacked100@1.0.0 supported Chart.js@3 :)
It has breaking change. you need register the plugin manualy.

import { Chart } from "chart.js";
import ChartjsPluginStacked100 from "chartjs-plugin-stacked100";

Chart.register(ChartjsPluginStacked100);

@jagdaleganesh
Copy link

Thank you

@mkismy
Copy link

mkismy commented Sep 13, 2021

Using the example on readme via CDN, it does not work as expected and become a normal bar chart.

<div style="width: 700px; height: 300px">
  <canvas id="my-chart"></canvas>
</div>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-stacked100"></script>
<script type="text/javascript">
Chart.register(ChartjsPluginStacked100);

new Chart(document.getElementById("my-chart"), {
  type: "bar",
  data: {
    labels: ["Foo", "Bar"],
    datasets: [
      { label: "bad", data: [5, 25], backgroundColor: "rgba(244, 143, 177, 0.6)" },
      { label: "better", data: [15, 10], backgroundColor: "rgba(255, 235, 59, 0.6)" },
      { label: "good", data: [10, 8], backgroundColor: "rgba(100, 181, 246, 0.6)" }
    ]
  },
  options: {
    indexAxis: "y",
    plugins: {
      stacked100: { enable: true }
    }
  }
});
</script>

image

When adding stacked option, the bar stacks but doesn't become a 100% stacked bar.

  options: {
    indexAxis: "y",
    scales: {
      x: { stacked: true },
      y: { stacked: true },
    },
    plugins: {
      stacked100: { enable: true }
    }
  }

image

@y-takey Can you check if there are anything wrong with the code above?

@y-takey
Copy link
Owner

y-takey commented Sep 14, 2021

@mkismy Thanks for the issue :)
Sorry, the example was wrong. here is correctly example.

Chart.register(ChartjsPluginStacked100.default);  // HERE!

new Chart(document.getElementById("my-chart"), {
  type: "bar",
  data: {
    labels: ["Foo", "Bar"],
    datasets: [
      { label: "bad", data: [5, 25], backgroundColor: "rgba(244, 143, 177, 0.6)" },
      { label: "better", data: [15, 10], backgroundColor: "rgba(255, 235, 59, 0.6)" },
      { label: "good", data: [10, 8], backgroundColor: "rgba(100, 181, 246, 0.6)" }
    ]
  },
  options: {
    indexAxis: "y",
    plugins: {
      stacked100: { enable: true }
    }
  }
});

I will fix readme later.

@mkismy
Copy link

mkismy commented Sep 14, 2021

Thank you 😁

@y-takey y-takey closed this as completed Sep 14, 2021
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

4 participants