Strikethrough on label text not working when using generateLabel

The default functionality of label item text having a strikethrough applied when clicking on it from within the legend is not working. I would like to fix this issue so the strikethrough is applied (or toggled off) when clicked and the corresponding data is hidden from or shown to the chart.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const outsourcedProductionNames = ["Development", "Content", "Design"];
const outsourcedProductionCounts = new Array(outsourcedProductionNames.length).fill(0);
// Function to truncate text and add ellipses
function truncateText(text, maxLength) {
if (text.length > maxLength) {
return text.substring(0, maxLength) + '...';
}
return text;
}
// Function to generate distinct colors
function generateDistinctColors(count) {
const colors = [];
for (let i = 0; i < count; i++) {
const hue = i * (360 / count);
colors.push(`hsl(${hue}, 100%, 75%)`);
}
return colors;
}
// Generate distinct colors for the chart
const colors = generateDistinctColors(outsourcedProductionNames.length);
const ctx = document.getElementById('allChartsOutsourcedProduction').getContext('2d');
new Chart(ctx, {
type: 'pie',
data: {
labels: outsourcedProductionNames,
datasets: [{
label: 'Outsourced Production',
data: outsourcedProductionCounts,
backgroundColor: colors,
borderColor: 'white',
borderWidth: 2
}]
},
options: {
aspectRatio: 1.5,
plugins: {
legend: {
labels: {
filter: (legendItem, data) => data.datasets[0].data[legendItem.index] != 0,
generateLabels: function(chart) {
return chart.data.labels.map((label, index) => {
return {
text: truncateText(label, 20),
fillStyle: chart.data.datasets[0].backgroundColor[index],
strokeStyle: undefined, // Remove the border color
lineWidth: 0, // Remove the border width
hidden: chart.getDatasetMeta(0).data[index].hidden,
index: index
};
});
}
}
},
tooltip: {
titleFont: {
family: "sans-serif",
weight: 900
},
callbacks: {
label: data => (' ' + data.parsed + ' Projects')
}
}
}
}
});
</code>
<code>const outsourcedProductionNames = ["Development", "Content", "Design"]; const outsourcedProductionCounts = new Array(outsourcedProductionNames.length).fill(0); // Function to truncate text and add ellipses function truncateText(text, maxLength) { if (text.length > maxLength) { return text.substring(0, maxLength) + '...'; } return text; } // Function to generate distinct colors function generateDistinctColors(count) { const colors = []; for (let i = 0; i < count; i++) { const hue = i * (360 / count); colors.push(`hsl(${hue}, 100%, 75%)`); } return colors; } // Generate distinct colors for the chart const colors = generateDistinctColors(outsourcedProductionNames.length); const ctx = document.getElementById('allChartsOutsourcedProduction').getContext('2d'); new Chart(ctx, { type: 'pie', data: { labels: outsourcedProductionNames, datasets: [{ label: 'Outsourced Production', data: outsourcedProductionCounts, backgroundColor: colors, borderColor: 'white', borderWidth: 2 }] }, options: { aspectRatio: 1.5, plugins: { legend: { labels: { filter: (legendItem, data) => data.datasets[0].data[legendItem.index] != 0, generateLabels: function(chart) { return chart.data.labels.map((label, index) => { return { text: truncateText(label, 20), fillStyle: chart.data.datasets[0].backgroundColor[index], strokeStyle: undefined, // Remove the border color lineWidth: 0, // Remove the border width hidden: chart.getDatasetMeta(0).data[index].hidden, index: index }; }); } } }, tooltip: { titleFont: { family: "sans-serif", weight: 900 }, callbacks: { label: data => (' ' + data.parsed + ' Projects') } } } } }); </code>
const outsourcedProductionNames = ["Development", "Content", "Design"];
const outsourcedProductionCounts = new Array(outsourcedProductionNames.length).fill(0);

      // Function to truncate text and add ellipses
      function truncateText(text, maxLength) {
          if (text.length > maxLength) {
              return text.substring(0, maxLength) + '...';
          }
          return text;
      }

      // Function to generate distinct colors
      function generateDistinctColors(count) {
          const colors = [];
          for (let i = 0; i < count; i++) {
              const hue = i * (360 / count);
              colors.push(`hsl(${hue}, 100%, 75%)`);
          }
          return colors;
      }

      // Generate distinct colors for the chart
      const colors = generateDistinctColors(outsourcedProductionNames.length);

      const ctx = document.getElementById('allChartsOutsourcedProduction').getContext('2d');
      new Chart(ctx, {
          type: 'pie',
          data: {
              labels: outsourcedProductionNames,
              datasets: [{
                  label: 'Outsourced Production',
                  data: outsourcedProductionCounts,
                  backgroundColor: colors,
                  borderColor: 'white',
                  borderWidth: 2
              }]
          },
          options: {
              aspectRatio: 1.5,
              plugins: {
                  legend: {
                      labels: {
                          filter: (legendItem, data) => data.datasets[0].data[legendItem.index] != 0,
                          generateLabels: function(chart) {
                              return chart.data.labels.map((label, index) => {
                                  return {
                                      text: truncateText(label, 20),
                                      fillStyle: chart.data.datasets[0].backgroundColor[index],
                                      strokeStyle: undefined, // Remove the border color
                                      lineWidth: 0, // Remove the border width
                                      hidden: chart.getDatasetMeta(0).data[index].hidden,
                                      index: index
                                  };
                              });
                          }
                      }
                  },
                  tooltip: {
                      titleFont: {
                          family: "sans-serif",
                          weight: 900
                      },
                      callbacks: {
                          label: data => (' ' + data.parsed + ' Projects')
                      }
                  }
              }
          }
      });

I have tried making a separate plugin for the strikethrough function. This worked to get the strike through, but it caused my tooltip styling, truncate function, and filter (having items not show in legend that have 0 results) to not work.

New contributor

James Murphy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật