Say I have an existing excel file with a chart. Is there a way to use markers to populate the chart values or do I have to set each cell value individually by name? What I want to do is take a data collection, loop through it setting the chart values without targeting specific cells by name. Thanks
Hi,
Thanks for the reply. With a chart in cells, I have to define the range (columns and rows) that the chart will use for data though. How can I do that programatically? I created a template that had a few columns and that was it. The first column was for categories, the second column was value1 and the third was value2.
Hi again,
I’ve attached the spreadsheet with chart range. I’m manually creating it as a template. As I mentioned, I’m using this as a template and the code will populate the category names in the categories column and then the data points in the value1 and value2 columns. There will be 3 rows of data points. So like I said the data fills the A1 through C4 and it looks like:
Hi,
Thanks for the information. The only thing I don’t like about that implementation is that I have to clear the series which also clears the custom series colors. Sounds like there is no way to get around that.
Hi,
worksheet.Cells[“A2”].PutValue(“group3”);
worksheet.Cells[“A3”].PutValue(“group4”);
worksheet.Cells[“A4”].PutValue(“group5”);
worksheet.Cells[“B2”].PutValue(100);
worksheet.Cells[“B3”].PutValue(222);
worksheet.Cells[“B4”].PutValue(218);
worksheet.Cells[“C2”].PutValue(412);
worksheet.Cells[“C3”].PutValue(102);
worksheet.Cells[“C4”].PutValue(239);
//Get the existing chart
Chart chart = worksheet.Charts[0];
//Refresh the chart according to new data
chart.Calculate();
workbook.Save(dir + “output.xlsx”);
wbd.net:
....The only thing I don't like about that implementation is that I have to clear the series which also clears the custom series colors. Sounds like there is no way to get around that.