C # Excel Generation

I am creating an excel genetic diagram from Epplus libary.

This is what I have successfully created.

enter image description here My table looks like this:

Mumbai Delhi Financial Dailies 103 279 Mainlines Dailies 35 55 Periodicals 0 6 Regional Dailies 68 212 

I'm stuck on how to add a color-coded legend on the left side of the chart, as shown in the image below.

Mumbai and Delhi are column names the table from which I am filling out the chart.

enter image description here

code below

 protected void addBarGraph(string r1,string r2,string r3,string r4) { try{ var chart1 = ws.Drawings.AddChart("xyz",eChartType.ColumnClustered3D) as ExcelBarChart ; chart1.SetPosition(1, 0, 1, 0); chart1.SetSize(600, 400); // chart1.Legend.Position = OfficeOpenXml.Drawing.Chart.eLegendPosition.Left; chart1.DataLabel.ShowValue = true; // chart1.DataLabel.ShowLegendKey = true; //chart1.DataLabel.ShowLeaderLines = true; // chart1.DataLabel.ShowSeriesName = true; // chart1.Legend.ToString(); // chart1.Legend.Add(); chart1.Series.Add(r1, r2); chart1.Series.Add(r3, r2); chart1.Series.Add(r4, r2); chart1.Style = OfficeOpenXml.Drawing.Chart.eChartStyle.Style26; chart1.Title.Text = "Some title"; } catch(Exception ex) { Response.Write(ex.Message); } } 

Please help me.

+4
source share
1 answer

Use the title property.

  var serie1 = chart1.Series.Add(r1, r2); serie1.Header = "Mumbai"; var serie2 = chart1.Series.Add(r3, r2); serie2.Header = "Delhi"; 
+3
source

Source: https://habr.com/ru/post/1483357/


All Articles