I have the report template like the attached sheet. I couldn’t find the property to design horizontal line in the graph. Can you please let me know the C# class file properties to build graph like that?.
I have written a sample code that will help you create your desired chart in the template file.
Note: I have used your template file to get source data for the chart.
Workbook excel = new Workbook();
Worksheet sheet = excel.Worksheets;
Cells cells = excel.Worksheets.Cells;
int x = excel.Worksheets.Add(SheetType.Chart);
ChartCollection charts = excel.Worksheets[x].Charts;
int chartIndex = charts.Add(ChartType.LineWithDataMarkers, 1, 3, 25, 12);
Chart chart = charts[chartIndex];
chart.Legend.Position = LegendPositionType.Bottom;
chart.Title.Text = “Lexus OT20 NLY, Contact Conversion”;
chart.Title.TextFont.Color = Color.Black;
chart.Title.TextFont.IsBold = true;
chart.Title.TextFont.Size = 18;
chart.Title.TextFont.Name = “Calibri”;
chart.NSeries.Add(“Report Data!E2:F34”, true);
chart.NSeries.XValues = “Report Data!A2:A34”;
NSeries nseries = chart.NSeries;
for (int i = 0; i < nseries.Count; i++)
nseries[i].Name = cells[0, i + 4].Value.ToString();
Thanks for your response. But i need to change the text direction for CategoryAxis. If i check manually in the attached report direction shows -57 degrees how to set this property?. Also I can’t able to display small horizontal rows. Plz help me.
Please add the following lines of code for your requirement:
chart.ValueAxis.MinorGridLines.IsVisible = true;
chart.CategoryAxis.TickLabels.Rotation = 57;
Thank you so much. This works for me.
How to set line color, datapoints color as Automatic while creation of graph like the attached doc ?
I tried with this one Series1.Area.Formatting = FormattingType.Automatic; but it is not working for me.
Below is the code i have used.
ASeries Series1 = chart.NSeries;
Series1.Name = “Net Yield%”;
Series1.Line.Weight = WeightType.WideLine;
Series1.Line.Style = LineType.Solid;
Series1.MarkerStyle = ChartMarkerType.SquareX;
Series1.MarkerSize = 8;
Series1.Area.Formatting = FormattingType.Automatic;
Please see the following sample code. I tried the code and it works as expected. Please refer to the code segment, you may add/change the code accordingly.
nseries.Line.Color = Color.Red;
nseries.MarkerForegroundColor = Color.Blue;
nseries.MarkerBackgroundColor = Color.Yellow;
nseries.MarkerSize = 8;
nseries.MarkerStyle = ChartMarkerType.SquareX;