简体   繁体   English

Microsoft ReportViewer:自定义Y轴标签以匹配特定格式

[英]Microsoft ReportViewer: Customize Y-Axis labels to match a specific format

I would like to customize the Y axis labels of a graph plotted with Microsoft ReportViewer. 我想自定义使用Microsoft ReportViewer绘制的图形的Y轴标签。 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. 例如,如果标签的值为12000000,则标签的值为12M,否则,如果标签的值为1200,则该值将保持为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 ) (为了帮助将我的问题具体化,我在谈论此窗口=> 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! 非常感谢你!

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. 我还向我的数据源添加了新的MillionsSymbol字段,并根据TotalValue更改了其内容。

Then, I can use this new field in the dialog Vertical Axis Properties -> Number -> Category[custom] 然后,我可以在“垂直轴属性->数字->类别[自定义]”对话框中使用此新字段

="0.00" & Fields!MillionsSymbol.Value

表达式窗口

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, #.##,...). 只要包含掩码(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: 最后结果:

在此处输入图片说明

*Image edited for clarity *为清晰起见编辑的图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM