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.

Tue Jan 08, 2019 11:17 am

Hey again, :D

i have again an question about creating barcharts. Is there a way to create a target-line for every series in my barchart just like this image but this line is from datapoint to datapoint different

a little bit like stairs (up and down)

2019-01-08_12h06_59.png
2019-01-08_12h06_59.png (6.3 KiB) Viewed 842 times


THX

Thomas

Semjasa
 
Posts: 36
Joined: Wed Dec 19, 2018 11:50 am

Wed Jan 09, 2019 6:41 am

Hi Thomas,

Thanks for your inquiry.
According to your information, I think that the error bar could meet your requirement. After testing, I find the data labels of series 2 is unable to set as invisible. I have posted this issue to our Dev team, we will let you know as soon as there is any update.
Below is my testing code, and attached are my files for your reference:
Code: Select all
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"F:\testing\xls test form\sample document\target line.xlsx");
            Worksheet sheet = workbook.Worksheets[0];

            //Add Chart and Set Chart Data Range
            Chart chart = sheet.Charts.Add(ExcelChartType.ColumnClustered);
            chart.DataRange = sheet.Range["A1:C5"];
            chart.SeriesDataFromRange = false;
            chart.PrimaryValueAxis.HasMajorGridLines = false;

            //Chart Position
            chart.LeftColumn = 1;
            chart.TopRow = 19;
            chart.RightColumn = 15;
            chart.BottomRow = 40;

            ChartSerie ser2 = chart.Series[1];
            //this code doesn't work
            ser2.DataPoints.DefaultDataPoint.DataLabels.HasValue = false;
            ser2.UsePrimaryAxis = true;
            //For adding error bar X, change the chart type as scatter marker.
            ser2.SerieType = ExcelChartType.ScatterMarkers;
            ser2.Format.MarkerStyle = ChartMarkerType.None;
           

            //add the error bar X for the serie
            var eb = ser2.ErrorBar(false,ErrorBarIncludeType.Both);
            eb.HasCap = false;
            eb.Border.Color = Color.Red;
            eb.Border.Weight = ChartLineWeightType.Medium;
            eb.NumberValue = 0.3;

            workbook.SaveToFile("CreatErrorBar16072.xlsx",ExcelVersion.Version2013);


Sincerely,
Betsy
E-iceblue support team
Attachments
SampleFiles.zip
(14.4 KiB) Downloaded 196 times
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Jan 09, 2019 7:28 am

THIS IS AMAZING!!!

Thank you this is perfect to see.

Thanks for this fast reply.

best regards
Thomas

Semjasa
 
Posts: 36
Joined: Wed Dec 19, 2018 11:50 am

Wed Jan 09, 2019 7:59 am

Hi Thomas,

I will inform you once the issue I mentioned is fixed. :D

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Jan 14, 2019 8:10 am

Hi Thomas,

After further investigation, we found the reason of the issue I mentioned before. When using the code "ser2.SerieType = ExcelChartType.ScatterMarkers", all settings of datapoints in that series would be clear, so you need to set the corresponding code after above code. Here is changed code for your kind reference:
Code: Select all
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"F:\testing\xls test form\sample document\target line.xlsx");
            Worksheet sheet = workbook.Worksheets[0];

            //Add Chart and Set Chart Data Range
            Chart chart = sheet.Charts.Add(ExcelChartType.ColumnClustered);
            chart.DataRange = sheet.Range["A1:C5"];
            chart.SeriesDataFromRange = false;
            chart.PrimaryValueAxis.HasMajorGridLines = false;

            //Chart Position
            chart.LeftColumn = 1;
            chart.TopRow = 19;
            chart.RightColumn = 15;
            chart.BottomRow = 40;

            ChartSerie ser2 = chart.Series[1];

            ser2.UsePrimaryAxis = true;
            //For adding error bar X, change the chart type as scatter marker.
            ser2.SerieType = ExcelChartType.ScatterMarkers;
            ser2.Format.MarkerStyle = ChartMarkerType.None;
            //change the position
            ser2.DataPoints.DefaultDataPoint.DataLabels.HasValue = false;
            //set the series name as invisible
            ser2.DataPoints.DefaultDataPoint.DataLabels.HasSeriesName = false;
            //set the category name as invisible
            ser2.DataPoints.DefaultDataPoint.DataLabels.HasCategoryName = false;

            //add the error bar X for the serie
            var eb = ser2.ErrorBar(false,ErrorBarIncludeType.Both);
            eb.HasCap = false;
            eb.Border.Color = Color.Red;
            eb.Border.Weight = ChartLineWeightType.Medium;
            eb.NumberValue = 0.3;

            workbook.SaveToFile("CreatErrorBar16072.xlsx",ExcelVersion.Version2013);


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Jan 18, 2019 6:37 am

Hi,

Greetings from E-iceblue.
Did the code I provided help you solve your issue?
Could you please give us some feedback at your convenience?

Best wishes,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Jan 25, 2019 9:53 am

entschuldigen sie bitte. ich habe im alltag einfach vergessen zu antworten. Es funktionert wunderbar wie alle dinge die man fragt.

Amazing Support!!!

Thanks a lot

Thomas

Semjasa
 
Posts: 36
Joined: Wed Dec 19, 2018 11:50 am

Fri Jan 25, 2019 9:58 am

Hi Thomas,

It is my pleasure to help you. :)
Please feel free to contact us if you need any help.
Have a nice day!

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.XLS