Graph Issue

Hi

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?.

Thanks
viswa

Hi Viswa,

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.
Sample code:

Workbook excel = new Workbook();
excel.Open(“e:\test\ReportTemplate.xlsx”);
Worksheet sheet = excel.Worksheets[0];
Cells cells = excel.Worksheets[0].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[0].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();



}

excel.Save(“e:\test\out.xlsx”);



Hi,

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.

Thanks,
Viswa

Hi Viswa,

Please add the following lines of code for your requirement:

chart.ValueAxis.MinorGridLines.IsVisible = true;
chart.CategoryAxis.TickLabels.Rotation = 57;


Thank you.

Thank you so much. This works for me.

Hi

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[0];
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;

Thanks,
viswa

Hi Viswa,

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[0].Line.Color = Color.Red;
nseries[0].MarkerForegroundColor = Color.Blue;
nseries[0].MarkerBackgroundColor = Color.Yellow;
nseries[0].MarkerSize = 8;
nseries[0].MarkerStyle = ChartMarkerType.SquareX;


Thank you.