How to display only zero Axis on Bar staked chart

Hello,i would like to know if it was possible to only display the zero on the axis of a barstacked chart ?
Thank you so much

@lolorek,
You can use the following workaround to get the desired result. The idea of the code is to set the distance between major tick marks to a value, which is bigger than the biggest value of a chart, and also to set the axes’ minimum and maximum scaling value bellow your major tick distance value. This code will return a document with a bar stacked chart, where only zero displayed on Y axis:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

var chart = builder.InsertChart(ChartType.BarStacked, 200, 200);

chart.Chart.AxisY.MajorUnit = 100;
chart.Chart.AxisY.Scaling.Minimum = new AxisBound(0);
chart.Chart.AxisY.Scaling.Maximum = new AxisBound(15);

doc.Save(@"C:\Temp\output.docx");

Please check the following document, produced by the code above:

If this method doesn’t suits you, please create manually and attach here your desired output document. We will then provide more information about your query.

Hello @sergey.lobanov and thank you so much for your answer.
The result is better with your code, but i have negative values and it’s displayed

Of course if i hidden the axis , the zero value is not displaying but the axis yes,with the following code
An other idea ?? :wink:
Thx

ChartAxis yAxis = chart.AxisY;
 
yAxis.ReverseOrder = false;
yAxis.Scaling.Type = AxisScaleType.Linear;
yAxis.Crosses = AxisCrosses.Custom;
yAxis.CrossesAt = 0;
yAxis.MajorUnit = 200;
yAxis.MinorUnit = 1; // 0 isn't possible
yAxis.Scaling.Minimum = new AxisBound(minMaxAxis.Min);
yAxis.Scaling.Maximum = new AxisBound(minMaxAxis.Max);
//yAxis.Hidden = true;

CaptureGraph.PNG (2.2 KB)

@lolorek,
In case of negative values, you may hide the Y axis and then use the Aspose.Words.Layout classes to insert a TextBox with zero value into your document separately from a chart. Please check the following code example:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);


var chart = builder.InsertChart(ChartType.BarStacked, 200, 200);
chart.Chart.Series.Add("Series 4",
        new[] { "Category 1", "Category 2", "Category 3", "Category 4", "Category 5" },
        new[] { 1.0, -8, 5, -6, 7 });

ChartAxis yAxis = chart.Chart.AxisY;

yAxis.MajorUnit = 200;
double axisMinimum = -15;
double axisMaximum = 15;
yAxis.Scaling.Minimum = new AxisBound(axisMinimum);
yAxis.Scaling.Maximum = new AxisBound(axisMaximum);
yAxis.Hidden = true;

var collector = new LayoutCollector(doc);
var enumerator = new LayoutEnumerator(doc);
enumerator.Current = collector.GetEntity(chart);

var tb = builder.InsertShape(ShapeType.TextBox, RelativeHorizontalPosition.LeftMargin, enumerator.Rectangle.X + 92.5, RelativeVerticalPosition.TopMargin, enumerator.Rectangle.Y + 162, 10, 10, WrapType.None);
tb.TextBox.FitShapeToText = true;
tb.Stroked = false;

tb.RemoveAllChildren();
Paragraph p = new Paragraph(doc);
tb.AppendChild(p);
builder.MoveTo(p);
builder.Write("0");


doc.Save(@"C:\Temp\output.docx");

Thank you so much @sergey.lobanov, it works fine ! :ok_hand: