0

I would like to customize the Y axis labels of a graph plotted with Microsoft ReportViewer. What I want is to have a logic like the following:

If (value>1000000)
   return value/1000000 & "M"
else 
   return value

For example if the value of the label is 12000000 then the label value will be 12M, otherwise if the label value is 1200 the value will remain 1200.

I have tried to customize the numeric format to obtain this kind of behaviour tring something like:

= iif(value>1000000,value/1000000 'M',value)

(to help contextualize my question, i'm talking about this window=> https://dotnetblurb.files.wordpress.com/2012/05/3.jpg)

but, as expected, it didn't work.

Googling didn't help much as well, it seems like this kind of customization is just not possible. Or is it?

Thank you very much!

Eux
  • 482
  • 7
  • 16

1 Answers1

0

I solved this issue using both the expressions window and altering the graph's datasource content.

In the method filling the data source I added the logic converting big numbers into smaller numbers:

reportModel.MillionsSymbol = "";
if (reportModel.TotalValue > 1000000)
{
      reportModel.TotalValue /= 1000000;
      reportModel.MillionsSymbol = "M ";
}

I also added the new MillionsSymbol field to my data source and I change its content based on the TotalValue.

Then, I can use this new field in the dialog Vertical Axis Properties -> Number -> Category[custom]

="0.00" & Fields!MillionsSymbol.Value

Expressions window

The trick here is that I wrote an expression that is returning a string containing the characters mask needed by the function that is formatting the axis numbers' label. In this string I can put anything as long as it contains the mask (0.00, #.##,...).

This method allows me to concatenate a variable to the value that is going to appear as a label for every tick of the vertical axis of the graph. It doesn't allow me to work on that value, since I didn't find any way to get access to it. This is why I altered the values in the data source. In this way, though, I'm changing the value of the graph points and then conseguently the vertical axis ticks' values.

Final result:

enter image description here

*Image edited for clarity

Eux
  • 482
  • 7
  • 16