Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Mon Apr 30, 2018 3:19 pm

My table ha the following values:
linechart1.PNG
linechart1.PNG (2.61 KiB) Viewed 2193 times


What I currently have is:
linechart2.PNG
linechart2.PNG (16.7 KiB) Viewed 2193 times


Is there a way to get this output?:
linechart3.PNG
linechart3.PNG (15.73 KiB) Viewed 2193 times



Furthermore, I noticed that the values are not the one of the table but the first day of the month. Why? Is this an Excel "feature"?


EDIT:
I create the Excel from scratch. First the cell are filled:

Code: Select all
IEnumerable<Tuple<DateTime, int>> mitarbeiterJahre = from s in statistikenPerYear
                                        from b in s.Value.Bueros
                                        where b.Key == keyValuePair.Key
                                        group b by Tuple.Create(b.Key, s.Key, b.Value) into g
                                        orderby g.Key.Item2 descending
                                        select Tuple.Create(g.Key.Item2, g.Sum(x => x.Value.Mitarbeiter));

cell = ws.Cell(16, 1);
cell.Style.Font.SetBold();
cell.Value = $"Anzahl Mitarbeiter";

cell = ws.Cell(17, 1);
cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
cell.Value = date.ToString("dd.MM.yyyy");
cell = ws.Cell(17, 2);
cell.Value = statistiken.Mitarbeiter;

for (int i = 0; i < mitarbeiterJahre.Count(); i++)
{
   cell = ws.Cell(18 + i, 1);
   cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
   cell.Value = mitarbeiterJahre.ElementAt(i).Item1.ToString("dd.MM.yyyy");
   cell = ws.Cell(18 + i, 2);
   cell.Value = mitarbeiterJahre.ElementAt(i).Item2;

}


Then the chart is created:

Code: Select all
Chart lineChart = sheet.Charts.Add(ExcelChartType.Line);
lineChart.ChartTitle = string.Empty;

lineChart.LeftColumn = 4;
lineChart.TopRow = 16;
lineChart.RightColumn = 12;
lineChart.BottomRow = 35;

lineChart.DataRange = sheet.Range["A17:B21"];
lineChart.SeriesDataFromRange = false;

lineChart.PrimaryValueAxis.Visible = false;
lineChart.PrimaryCategoryAxis.Visible = false;

ChartSerie csLine = lineChart.Series[0];

csLine.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
for (int i = 0; i < csLine.Values.Count; i++)
{
   csLine.DataPoints[i].DataLabels.Color = Color.Black;
   csLine.DataPoints[i].DataLabels.Position = DataLabelPositionType.Below;
   csLine.DataPoints[i].DataLabels.Delimiter = " - ";
   csLine.DataPoints[i].DataLabels.HasValue = true;
   csLine.DataPoints[i].DataLabels.HasCategoryName = true;
   
   csLine.DataPoints[i].DataFormat.MarkerStyle = ChartMarkerType.Circle;
   csLine.DataPoints[i].DataFormat.MarkerSize = 7;
   csLine.DataPoints[i].DataFormat.MarkerForegroundColor = Color.FromArgb(74, 126, 187);
   csLine.DataPoints[i].DataFormat.MarkerBackgroundColor = Color.FromArgb(74, 126, 187);

}

lineChart.PlotArea.Fill.Visible = false;
lineChart.Legend.Delete();


I'm working with "de-DE" CultureInfo.
Last edited by emaborsa2 on Thu May 03, 2018 8:04 am, edited 1 time in total.

emaborsa2
 
Posts: 6
Joined: Tue Feb 06, 2018 7:24 am
Location: Italy

Tue May 01, 2018 4:48 am

Dear Emanuel,

Thanks for your inquiry.
Could you please attach your input Excel file, your full code as well as your region setting (e.g. China/Chinese ) here to help us look into your issue accurately? Then we will provide more information on your requirement.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Thu May 03, 2018 8:05 am

I added some information. See above.

emaborsa2
 
Posts: 6
Joined: Tue Feb 06, 2018 7:24 am
Location: Italy

Thu May 03, 2018 8:32 am

I just figured it out! I had to add the following line:

Code: Select all
lineChart.PrimaryCategoryAxis.CategoryType = CategoryType.Category;

emaborsa2
 
Posts: 6
Joined: Tue Feb 06, 2018 7:24 am
Location: Italy

Thu May 03, 2018 9:29 am

Hello,

I am glad to hear that you find the solution.
Please feel free to contact us if you need assistance in the future.
Wish you all the best!

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.XLS