Dear Support,
I need make a chart with high, low , and average data. I’m be able to build it in excel file using high-low line feature flowing this tutroial
http://www.agentjim.com/MVP/Excel/Charts/MaxMin2011/Average_Value_Chart_in_Excel_2011.html
I had attached the out put file.
I was wander if I can make it using aspose API IN C# ?
Can you provide me the code how to make the high-low line?
Thank you!
Thanks for your posting and considering Aspose APIs.
Please see the following sample code. You need to set the Chart.NSeries[idx].HasHiLoLines property as true to create hi lo lines in chart. Please read the comments inside the code. I have also attached the output Excel file generated by the code. Please also see the chart screenshot given below.
outputHiLoChart.zip (7.5 KB)
C#
//Create workbook
Workbook wb = new Workbook();
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Write some data for the chart in cells
ws.Cells["A1"].PutValue("Parks");
ws.Cells["B1"].PutValue("Hotels");
ws.Cells["A2"].PutValue(3);
ws.Cells["A3"].PutValue(1);
ws.Cells["A4"].PutValue(6);
ws.Cells["A5"].PutValue(4);
ws.Cells["B2"].PutValue(6);
ws.Cells["B3"].PutValue(4);
ws.Cells["B4"].PutValue(3);
ws.Cells["B5"].PutValue(1);
//Create line chart
int idx = ws.Charts.Add(ChartType.Line,6, 3, 22, 11);
//Access the chart
Chart ch = ws.Charts[idx];
//Set the chart data range
ch.SetChartDataRange("A1:B5", true);
//Set the chart title and its text
ch.Title.Text = "Hi Lo Lines - Chart";
ch.Title.IsVisible = true;
//Set the series names
ch.NSeries[0].Name = "=A1";
ch.NSeries[1].Name = "=B1";
//------------------------------
//------------------------------
//This line is important
//Make Hi Lo Lines
ch.NSeries[0].HasHiLoLines = true;
//Make both series invisible
ch.NSeries[0].Border.IsVisible = false;
ch.NSeries[1].Border.IsVisible = false;
//Set the plot area of the foreground
ch.PlotArea.Area.ForegroundColor = Color.White;
//Save the workbook
wb.Save("outputHiLoChart.xlsx");
Thank you so much! It worked!
How can I change the color and size of the high low line?
Thanks for using Aspose APIs.
Please add these two lines in the existing code and it will set the color and size of hi lo lines. Please see the output Excel file and screenshot after adding these lines.
Download Link:
Output Excel File.zip (7.5 KB)
C#
//These are new lines to set weight and color
ch.NSeries[0].HiLoLines.WeightPt = 4;
ch.NSeries[0].HiLoLines.Color = Color.Yellow;