Is that possible to add a condition to check whether the value is 0 then return empty string?

hi @ivan.lyagin , is that possible to add a condition to check whether the value is 0 then return empty string?

@leoteoh Sure you can. For example you can use condition in your expression like this:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("<<[val>0?val.ToString():\"\"]>>");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, 0, "val");
doc.Save(@"C:\Temp\out.docx");

Also, you can use LINQ Reporting Engine conditional block.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("<<if [val>0]>><<[val]>><</if>>");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, 0, "val");
doc.Save(@"C:\Temp\out.docx");

Hi @alexey.noskov Thanks for the reply, but I need apply the condition in the chart for y axes condition

How can I return empty string if the value is 0?

<<[y Where(x => x.data = "foo").select(x => x.value) == 0 ? "" : Where(x => x.data = "foo").select(x => x.value).ToString()]>>

@leoteoh Could you please attach your template, sample data and expected output here for our reference? We will check the them and provide you more information.

Doc1.docx (27.6 KB)

Here is the template, so I want to hide the chart y axis label when the value is equals to 0.

@leoteoh Thank you for additional information. But could you please also attach your sample data and expected output?

class Chart {
    public string name {get;set;}
    public int value {get;set;}
}

List<Chart> chart = new List<Chart> {
    new Chart {
        name = "A",
        value = 0
    },
 new Chart {
        name = "B",
        value = 1
    },
 new Chart {
        name = "C",
        value = 2
    }
}

From the image you can see there is a zero in the chart, I would like to hide the 0 when the value is equals to 0, but it is a y axis, im not sure how to do for the y axis.

@leoteoh Thank you for additional information. What you are trying to hide is not Y-Axis, it is data label. You can use custom number format like this #"" to hide zero values. for example as described here:
https://www.extendoffice.com/documents/excel/2031-excel-hide-zero-data-labels.html

Thanks, the problem is resolved

1 Like