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

46 lines
1.0KB

  1. HTMLWidgets.widget({
  2. name: 'frappeChart',
  3. type: 'output',
  4. factory: function(el, width, height) {
  5. // TODO: define shared variables for this instance
  6. // helper function to prep the data
  7. const prepareChartData = function(data) {
  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(data)[0]
  11. let columns = Object.keys(data).slice(1)
  12. // First column in x.data is the labels
  13. chartData.labels = 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: data[col]})
  17. })
  18. return chartData
  19. }
  20. return {
  21. renderValue: function(x) {
  22. x.data = prepareChartData(x.data)
  23. const chart = new frappe.Chart(el, x)
  24. },
  25. resize: function(width, height) {
  26. // TODO: code to re-render the widget with a new size
  27. }
  28. };
  29. }
  30. });