I have an HTML file. In that we have a script tag related to bar charts. I want to replace that barchart's data value and label value to change the barcharts appearance. I want to do this with a C# console application. I have tried to do it using Html agility pack's replace function, but it's only editing strings. How to edit or replace values and labels?
Is there any way to achieve this using Html agility pack or any other way without using agility pack? (or) any dynamic function in javascript which will replace values by placing it in html?
What I have tried:
Below is the javascript snippet inside the HTML file:
script src="js/chart.js"></script>
<script>
const samplechart = document.getElementById('samplechart ');
var barChartData = {
labels: ["Dec", "Jan", "Feb", "Mar", "Apr", "May"],
datasets: [{
label: "Closed",
type: "bar",
data: [7, 8, 9, 12, 4, 3],
backgroundColor: '#3f54b5'
},
{
label: "Open",
type: "bar",
data: [0, 2, 10, 1, 3, 2],
backgroundColor: '#8bc34a'
}
}
new Chart(samplechart, {
data: barChartData,
borderWidth: 0,
options: {
plugins: {
title: {
display: true,
text: 'sample cases',
color: "#000",
font: {
size: 24
}
}
},
});
</Script>
Code for loading it using html agility pack and replacing its name only (only this works, but I want to replace labels: and data: of barcharts.)
HtmlDocument document2 = new HtmlDocument();
document2.Load(@"D:\Downloads\sample1.html");
HtmlNode[] nodes = document2.DocumentNode.SelectNodes("//script").ToArray();
nodes[1].InnerHtml = nodes[1].InnerHtml.Replace("Reportchart","Samplechart");
document2.Save(@"D:\Downloads\sample1.html");
I have an HTML file. In that we have a script tag related to bar charts. I want to replace that barchart's data value and label value to change the barcharts appearance. I want to do this with a C#/ WPF/console application. I have tried to do it using Html agility pack's replace function, but it's only editing strings. How to edit or replace values and labels?
Below is the javascript snippet inside the HTML file:
script src="js/chart.js"></script>
<script>
const samplechart = document.getElementById('samplechart ');
var barChartData = {
labels: ["Dec", "Jan", "Feb", "Mar", "Apr", "May"],
datasets: [{
label: "Closed",
type: "bar",
data: [7, 8, 9, 12, 4, 3],
backgroundColor: '#3f54b5'
},
{
label: "Open",
type: "bar",
data: [0, 2, 10, 1, 3, 2],
backgroundColor: '#8bc34a'
}
}
new Chart(samplechart, {
data: barChartData,
borderWidth: 0,
options: {
plugins: {
title: {
display: true,
text: 'sample cases',
color: "#000",
font: {
size: 24
}
}
},
});
</Script;
Code for loading it using html agility pack and replacing its name only (only this works, but I want to replace labels: and data: of barcharts.)
HtmlDocument document2 = new HtmlDocument();
document2.Load(@"D:\Downloads\sample1.html");
HtmlNode[] nodes = document2.DocumentNode.SelectNodes("//script").ToArray();
nodes[1].InnerHtml = nodes[1].InnerHtml.Replace("Reportchart","Samplechart");
document2.Save(@"D:\Downloads\sample1.html");
Is there any way to achieve this using Html agility pack or any other way without using agility pack? (or) any dynamic function in javascript which will replace values by placing it in html?