Share via


SSRS: Change the legend shape

I was able to do this with a matrix. First you have to insert a rectangle in the cell you want to use for the legend. Then the assign the background color of the rectangle to the column in an expression e.g. =Fields!ColorHex.Value. Next insert the circle image over top of the rectangle.

You should be able to use the same dataset for the matrix (legend) as you do for the chart. You'll need to add a column for the ColorHex values to your dataset. Then you can also reference the same column in the chart for the colors.

Report Preview:

https://i.stack.imgur.com/Vs2Ab.png

Circle .png file with transparency:

I created the image using GIMP (GNU Image Manipulation Program)

https://i.stack.imgur.com/NXy8j.png

Example SQL for color hex codes

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

Example XML for the .rdl report:

<?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>