Hello Team,
i want to draw a multi series graph, in the second series i should show dot graph i have drawn but i want to show the colors for dots based on some condition, i am pasting my sample code here, could you help me in achieving it,
Thanks in advance
string[] colHeaders = new string[] { “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”, “K”, “L”, “M”, “N”, “O”, “P”, “Q”, “R”, “S”, “T”, “U”, “V”, “W”, “X”, “Y”, “Z”,
“AA”,“AB”,“AC”,“AD”,“AE”,“AF”,“AG”,“AH”,“AI”,“AJ”,“AK”,“AL”,“AM”,“AN”,“AO”,“AP”,“AQ”,“AR”,“AS”,“AT”,“AU”,“AV”,“AW”,“AX”,“AY”,“AZ”
};
Aspose.Cells.License lic = new License();
lic.SetLicense(“Aspose.Cells.lic”);
Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets[0];
Cells cells = ws.Cells;
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn(“Name”, typeof(string)));
dt.Columns.Add(new DataColumn(“Value1”, typeof(int)));
dt.Columns.Add(new DataColumn(“Value2”, typeof(int)));
dt.Rows.Add("ABC", 40, 10);
dt.Rows.Add("DEF", 20, 60);
dt.Rows.Add("GHI", 60, 50);
dt.Rows.Add("IJK", 80, 30);
dt.Rows.Add("KLM", 100, 200);
for (int colindex = 0; colindex < dt.Columns.Count - 1; colindex++)
{
Cell cel = cells[colHeaders[colindex] + "1"];
cel.PutValue(dt.Columns[colindex].ColumnName);
}
int rowIndex = 2;
foreach (DataRow dr in dt.Rows)
{
for (int colindex = 0; colindex < dt.Columns.Count; colindex++)
{
Cell cel = cells[colHeaders[colindex] + rowIndex.ToString()];
cel.PutValue(dr[colindex]);
}
rowIndex++;
}
ws.Name = "ChartData";
int chartSheetIndex = wb.Worksheets.Add();
Worksheet chartsheet = wb.Worksheets[chartSheetIndex];
Cells chartCells = chartsheet.Cells;
int chartIndex = chartsheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 2, 0, 33, 17);
Aspose.Cells.Charts.Chart chart = chartsheet.Charts[chartIndex];
string categorySeries = "=ChartData!A2:A6";
string dataSeries = "=ChartData!B2:B6";
string growthSeries = "=ChartData!C2:C6";
chart.NSeries.Add(dataSeries, true);
chart.NSeries.Add(growthSeries, true);
chart.NSeries[1].Type = Aspose.Cells.Charts.ChartType.Scatter;
chart.NSeries[1].PlotOnSecondAxis = true;
chart.NSeries.CategoryData = categorySeries;
for (int pCount = 0; pCount < chart.NSeries[1].Points.Count - 1; pCount++)
{
var valueCell = cells.GetCell(pCount + 1, 2);
var value = Convert.ToInt32(valueCell.Value);
if (Convert.ToInt32(value) > 50)
chart.NSeries[1].Points[pCount].Area.ForegroundColor = System.Drawing.Color.Green;
else
chart.NSeries[1].Points[pCount].Area.ForegroundColor = System.Drawing.Color.Green;
}
chartsheet.Name = "Dot chart";
wb.Save(@"C:\ExportDirectory\DotChart.xlsx");