Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

44 lines
973B

  1. HTMLWidgets.widget({
  2. name: 'frappeChart',
  3. type: 'output',
  4. factory: function(el, width, height) {
  5. // TODO: define shared variables for this instance
  6. return {
  7. renderValue: function(x) {
  8. const chartData = {labels: [], datasets: []}
  9. // Get keys of data, assume that first entry is for labels, the rest are data
  10. let labelColumn = Object.keys(x.data)[0]
  11. let columns = Object.keys(x.data).slice(1)
  12. // First column in x.data is the labels
  13. chartData.labels = x.data[labelColumn]
  14. // Create an appropriate object for each column, reformat data and add to chartData
  15. columns.forEach(function(col) {
  16. chartData.datasets.push({name: col, values: x.data[col]})
  17. })
  18. x.data = chartData
  19. const chart = new frappe.Chart(el, x)
  20. },
  21. resize: function(width, height) {
  22. // TODO: code to re-render the widget with a new size
  23. }
  24. };
  25. }
  26. });