在SSRS中更改图例形状

时间:2018-10-22 23:15:46

标签: reporting-services charts formatting

我收到了将其中一个报表中的图例的形状从矩形更改为圆形的请求,

当前报告如下所示

screenshot

但所需的形状如下所示

screenshot

我检查了图例的属性,但是找不到改变形状或使用图像的方法。

有什么想法可以实现吗?

谢谢

1 个答案:

答案 0 :(得分:3)

我能够用矩阵做到这一点。首先,您必须在要用于图例的单元格中插入一个矩形。然后将矩形的背景颜色分配给表达式中的列,例如=Fields!ColorHex.Value。接下来,将圆形图像插入矩形上方。

您应该能够使用与图表相同的数据集(图例)。您需要为数据集中的ColorHex值添加一列。然后,您还可以参考图表中同一列的颜色。

报告预览:

screenshot

将.png文件透明化:

我使用GIMP (GNU Image Manipulation Program)

创建了图像

Circle

彩色十六进制代码的示例SQL

SELECT tbl.* FROM (VALUES
  ( '#90EE90', 'Due next month')
, ( '#FAFAD2', 'Due this month')
, ( '#FFB6C1', 'Overdue')
) tbl ([ColorHex], [GroupType]) 

.rdl报告的XML示例:

<?xml version="1.0" encoding="utf-8"?>
<Report MustUnderstand="df" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:df="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition/defaultfontfamily">
  <df:DefaultFontFamily>Segoe UI</df:DefaultFontFamily>
  <AutoRefresh>0</AutoRefresh>
  <DataSources>
    <DataSource Name="YourDataSource">
      <DataSourceReference>YourDataSource</DataSourceReference>
      <rd:SecurityType>None</rd:SecurityType>
      <rd:DataSourceID>68eb8e17-19b1-4ab3-8315-91c1cb31c63a</rd:DataSourceID>
    </DataSource>
  </DataSources>
  <DataSets>
    <DataSet Name="DataSet1">
      <Query>
        <DataSourceName>YourDataSource</DataSourceName>
        <CommandText>SELECT tbl.* FROM (VALUES
  ( '#90EE90', 'Due next month')
, ( '#FAFAD2', 'Due this month')
, ( '#FFB6C1', 'Overdue')
) tbl ([ColorHex], [GroupType]) </CommandText>
      </Query>
      <Fields>
        <Field Name="ColorHex">
          <DataField>ColorHex</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="GroupType">
          <DataField>GroupType</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
      </Fields>
    </DataSet>
  </DataSets>
  <ReportSections>
    <ReportSection>
      <Body>
        <ReportItems>
          <Tablix Name="Tablix3">
            <TablixBody>
              <TablixColumns>
                <TablixColumn>
                  <Width>0.9125cm</Width>
                </TablixColumn>
                <TablixColumn>
                  <Width>3.21438cm</Width>
                </TablixColumn>
              </TablixColumns>
              <TablixRows>
                <TablixRow>
                  <Height>0.89146cm</Height>
                  <TablixCells>
                    <TablixCell>
                      <CellContents>
                        <Rectangle Name="Rectangle3">
                          <ReportItems>
                            <Image Name="Image3">
                              <Source>Embedded</Source>
                              <Value>legend_template</Value>
                              <Sizing>FitProportional</Sizing>
                              <Height>0.89146cm</Height>
                              <Width>0.9125cm</Width>
                              <Style>
                                <Border>
                                  <Style>None</Style>
                                </Border>
                              </Style>
                            </Image>
                          </ReportItems>
                          <KeepTogether>true</KeepTogether>
                          <Style>
                            <Border>
                              <Style>None</Style>
                            </Border>
                            <RightBorder>
                              <Color>White</Color>
                              <Style>Solid</Style>
                            </RightBorder>
                            <BackgroundColor>=Fields!ColorHex.Value</BackgroundColor>
                          </Style>
                        </Rectangle>
                      </CellContents>
                    </TablixCell>
                    <TablixCell>
                      <CellContents>
                        <Textbox Name="GroupType1">
                          <CanGrow>true</CanGrow>
                          <KeepTogether>true</KeepTogether>
                          <Paragraphs>
                            <Paragraph>
                              <TextRuns>
                                <TextRun>
                                  <Value>=Fields!GroupType.Value</Value>
                                  <Style>
                                    <FontFamily>Calibri</FontFamily>
                                  </Style>
                                </TextRun>
                              </TextRuns>
                              <Style />
                            </Paragraph>
                          </Paragraphs>
                          <rd:DefaultName>GroupType1</rd:DefaultName>
                          <Style>
                            <Border>
                              <Color>LightGrey</Color>
                              <Style>None</Style>
                            </Border>
                            <VerticalAlign>Middle</VerticalAlign>
                            <PaddingLeft>2pt</PaddingLeft>
                            <PaddingRight>2pt</PaddingRight>
                            <PaddingTop>2pt</PaddingTop>
                            <PaddingBottom>2pt</PaddingBottom>
                          </Style>
                        </Textbox>
                      </CellContents>
                    </TablixCell>
                  </TablixCells>
                </TablixRow>
              </TablixRows>
            </TablixBody>
            <TablixColumnHierarchy>
              <TablixMembers>
                <TablixMember>
                  <Group Name="GroupType">
                    <GroupExpressions>
                      <GroupExpression>=Fields!GroupType.Value</GroupExpression>
                    </GroupExpressions>
                  </Group>
                  <SortExpressions>
                    <SortExpression>
                      <Value>=Fields!GroupType.Value</Value>
                    </SortExpression>
                  </SortExpressions>
                  <TablixMembers>
                    <TablixMember />
                    <TablixMember />
                  </TablixMembers>
                </TablixMember>
              </TablixMembers>
            </TablixColumnHierarchy>
            <TablixRowHierarchy>
              <TablixMembers>
                <TablixMember>
                  <Group Name="RowGroup">
                    <GroupExpressions>
                      <GroupExpression />
                    </GroupExpressions>
                  </Group>
                  <TablixHeader>
                    <Size>0.07938cm</Size>
                    <CellContents>
                      <Textbox Name="Textbox9">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value />
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style />
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>Textbox9</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>None</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                    </CellContents>
                  </TablixHeader>
                </TablixMember>
              </TablixMembers>
            </TablixRowHierarchy>
            <DataSetName>DataSet1</DataSetName>
            <Height>0.89146cm</Height>
            <Width>4.20625cm</Width>
            <Style>
              <Border>
                <Style>None</Style>
              </Border>
            </Style>
          </Tablix>
        </ReportItems>
        <Height>0.35097in</Height>
        <Style />
      </Body>
      <Width>1.656in</Width>
      <Page>
        <PageHeight>21cm</PageHeight>
        <PageWidth>29.7cm</PageWidth>
        <LeftMargin>0.75cm</LeftMargin>
        <RightMargin>0.75cm</RightMargin>
        <TopMargin>0.75cm</TopMargin>
        <BottomMargin>0.75cm</BottomMargin>
        <ColumnSpacing>0.13cm</ColumnSpacing>
        <Style />
      </Page>
    </ReportSection>
  </ReportSections>
  <ReportParametersLayout>
    <GridLayoutDefinition>
      <NumberOfColumns>2</NumberOfColumns>
      <NumberOfRows>4</NumberOfRows>
    </GridLayoutDefinition>
  </ReportParametersLayout>
  <EmbeddedImages>
    <EmbeddedImage Name="legend_template">
      <MIMEType>image/png</MIMEType>
      <ImageData>iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsSAAALEgHS3X78AAAAB3RJTUUH4goXAjEeL/CJEQAAAZNJREFUeNrt3dFxwzAMg2GL1/1Xdh6yQNujSNH+MEBD4hfg+nqN1n3f90VtChYAAAABAAABAADV6+fk4dZaK+PnnPyus04aLsvwSUDaAVSZfiqMNgDdxp8CohzAacZ3gwjm985YkoAJxnelIZjfO/u2BEw2vjINwfzenYL5vbsF83t3DOb37hrM7905mN+7u78HNCuc/t4UBPN7IaigiRXk9Od5EszvhaCCJlWQ05/vkQRMSYDTvycFEjD5TZiKAKiffTUkASoIADoZgP7f+xyQABUEAAEAAAEAAAEAAAEAAAEAAAEAAAEAAHUD8MWu/9dvvJMAFQQAnQ7Ac2BP/0uACqLIjhT9zSsJmFRBUpDvkQRMewhLQa43UfVBzFdBz3oPkIIcL6Lrg5mvgmZXkBTk7B6nDPJG81Mr6E0QMneNUwd7g/lbHsJPhrBjt5gy6BPNv66CGzSm/6P3bn9i+gLTZy+9RWlKGio9iacuNmVGF7k1Hw5XGb71KsNOGC7zLAbiOls647cgAgAAAgAAAgAA+uoD75Psfe3m0nIAAAAASUVORK5CYII=</ImageData>
    </EmbeddedImage>
  </EmbeddedImages>
  <rd:ReportUnitType>Cm</rd:ReportUnitType>
  <rd:ReportID>6203a576-d7cc-4b57-9a9b-12cf325d6203</rd:ReportID>
</Report>