自定义 X 轴和 Y 轴属性(教程)Customize X-axis and Y-axis properties (Tutorial)

在本教程中,你会学习很多用于自定义视觉对象的 X 轴和 Y 轴的不同方式。In this tutorial you'll learn many different ways to customize the X-axis and Y-axis of your visuals. 并非所有视觉对象都具有轴或是可以自定义;例如,饼图没有轴。Not all visuals have axes or can be customized; Pie charts, for example, don't have axes. 而且自定义选项因视觉对象而异,选项太多,无法在一篇文章中进行介绍。And customization options vary from visual to visual, too many options to cover in a single article. 因此我们讨论一些最常用的轴自定义,使你可以熟练地在 Power BI 报表画布中使用视觉对象格式设置选项卡。So we'll take a look at some of the most-used axes customizations and get you comfortable using the visual formatting tab in the Power BI report canvas.

备注

此页面适用于 Power BI 服务和 Power BI Desktop。This page applies to both Power BI service and Power BI Desktop. 这些自定义在选择”格式”(滚筒刷图标 )时可用,在 Power BI Desktop 中也可用。These customizations, which are available when the Format (the paint roller icon ) is selected, are also available in Power BI Desktop.

请观看下面的视频,Amanda 将演示如何自定义 X 和 Y 轴,以及各种用于在使用向上钻取和向下钻取时控制串联的方法。Watch Amanda customize her X and Y axes and demonstrate the various ways to control concatenation when using drill-up and drill-down. 然后,按照视频下方的分步说明操作,用“零售分析”示例自行尝试一下。Then follow the step-by-step instructions below the video to try it out yourself using the Retail Analysis sample.

在报表中自定义可视化效果 X 轴Customizing visualization X-axes in reports

创建堆积图可视化效果Create a stacked chart visualization

登录到 Power BI 服务,在编辑视图中打开零售分析示例报表。Sign in to the Power BI service and open the Retail Analysis Sample report in Editing View. 要遵循示例执行操作,请连接到零售分析示例To follow along, connect to the Retail Analysis sample.

  1. 新建一个柱形图,按会计月份显示今年和去年的销售额。Create a new column chart that shows this year's sales and last year's sales value by fiscal month.
  2. 转换为堆积柱形图。Convert it to a Stacked column chart.

自定义 X 轴Customize the X axis

  1. 在“可视化效果和筛选器”窗格中,选择“格式”(滚筒刷图标 )以显示自定义选项。In the Visualizations and Filters pane, select Format (the paint roller icon ) to reveal the customization options.
  2. 展开 X 轴选项。Expand the X-Axis options.

  3. 通过选择“打开”(或“关闭”)滑块来打开和关闭 X 轴。Turn the X-axis on and off by selecting the On (or Off) slider. 现在,将它保留为打开For now, leave it On. 导致用户想要禁用 Y 轴的一个原因是,节省空间以显示更多数据。One reason you might want to turn off the X-axis is to save space for more data.

  4. 设置文字颜色、文本大小和字体。Format the text color, size, and font. 在此示例中,我们已将“文字颜色”设置为“黑色”,将“文本大小”设置为“14”,并将“字体”设置为“Arial Black”。In this example we've set text Color to black, Text Size to 14, and Font to Arial Black.
  5. 启用 X 轴标题,并显示 X 轴的名称(在此例中,为 FiscalMonth)。Turn the X-axis Title On and display the name of the X axis -- in this case, FiscalMonth.
  6. 设置标题的文字颜色、文本大小和字体。Format the title text color, size, and font. 在此示例中,我们已将“标题颜色”设置为“橙色”,将“轴标题”更改为“会计月份”,并将“标题文本大小”设置为“21”。In this example we've set Title color to orange, changed Axis title to Fiscal Month, and set Title text size to 21.
  7. 若要按 FiscalMonth 排序,请依次选择图表右上角的省略号 (...) 和“按 FiscalMonth 排序”。To sort by FiscalMonth, select the ellipses (...) in the top-right corner of the chart and select Sort By FiscalMonth.

    进行这些自定义之后,柱形图应如下所示:After all these customizations, your column chart should look something like this:

若要还原现已完成的所有 X 轴自定义,请选择“X 轴”自定义窗格底部的“还原为默认值”。To revert all the X-axis customization you've done so far, select Revert To Default at the bottom of the X-axis customization pane.

自定义 Y 轴Customize the Y axis

  1. 展开“Y 轴”选项。Expand the Y-Axis options.

  2. 选择“开”(或“关”)滑块,启用(或禁用)Y 轴。Turn the Y-axis on and off by selecting the On (or Off) slider. 现在,将它保留为打开For now, leave it On. 导致用户要禁用 Y 轴的一个原因是,为了节省空间以显示更多数据。One reason you might want to turn off the Y-axis is to save space for more data.

  3. 将 Y 轴的“位置”改为“右”。Move the Y-Axis Position to the right.
  4. 设置文字颜色、文本大小和字体。Format the text color, size, and font. 在此示例中,我们已将“文字颜色”设置为“黑色”,将“文本大小”设置为“14”,并将“字体”设置为“Arial Black”。In this example we've set text Color to black, Text Size to 14, and Font to Arial Black.
  5. 保持“显示单元”设置为“百万”,且“值小数位”设置为“零”不变。Keep Display units set to Millions and Value decimal places to zero.
  6. 对于此可视化效果,显示 Y 轴标题并不会优化视觉对象,所以保持“标题”设置为“关”不变。For this visuaization, having a Y-axis title doesn't improve the visual, so leave Title turned Off.
  7. 让我们将“颜色”更改为“深灰色”,并将“笔划”增至“2”,以突出显示网格线。Let's make the gridlines stand out by changing the Color to a dark grey and increasing Stroke to 2.

    进行这些自定义之后,柱形图应如下所示:After all these customizations, your column chart should look something like this:

自定义具有双 Y 轴的可视化效果Customizing visualizations with dual Y-axes

首先会创建一个组合图,它显示商店计数对销售额的影响。First you'll create a Combo chart that looks at the impact store count has on sales. 此图表与组合图教程中创建的图表相同。This is the same chart that is created in the Combo chart Tutorial. 随后你会对双 Y 轴设置格式。Then you'll format the dual Y-axes.

创建具有两个 Y 轴的图表Create a chart with two Y-axes

  1. 新建折线图,按“时间 > FiscalMonth”跟踪“销售额 > 去年毛利率”。Create a new line chart that tracks Sales > Gross Margin last year % by Time > FiscalMonth.
  2. 通过选择省略号 (...),然后选择“按月进行排序”来按月对视觉对象排序。Sort the visual by month by selecting the ellipses (...) and choosing Sort by Month

[NOTE]: For help sorting by month, see sorting by other criteria

  1. 一月的 GM% 是 35%,在四月达到峰值 45%,在七月下降,在八月再次达到峰值。In January GM% was 35%, peaked at 45% in April, dropped in July and peaked again in August. 去年和本年度的销售额是否会呈现类似模式?Will we see a similar pattern in sales last year and this year?
  2. 本年度销售额 > 值去年销售额添加到折线图。Add This Year Sales > Value and Last Year Sales to the line chart. “去年毛利率”的比例尺(沿 0% 去年毛利率网格线的蓝线)比“销售额”的比例尺小得多,这样就更难比较了。The scale of GM% Last Year (the blue line running along the 0M% gridline) is much smaller than the scale of Sales which makes it difficult to compare. 而且,Y 轴标签百分比很不合理。And the Y-Axis label percentages are ridiculous.

  1. 若要使视觉对象更易于查看和解释,请将折线图转换为折线和堆积柱形图。To make the visual easier to read and interpret, convert the line chart to a Line and Stacked Column chart.

  2. 去年毛利率列值拖动到行值中。Drag Gross Margin Last Year % from Column Values into Line Values. 现在拥有的是上面创建的堆积柱形图和折线图。What we have now is the stacked column chart we created above plus a line chart. (可以视需要利用上面学到的知识,设置坐标轴的字体颜色和文本大小。)(Optionally, use what you learned above to format the axes font color and size.)

Power BI 会创建两个轴,从而允许数据集以不同方式缩放;左侧度量值是美元,右侧度量值是百分比。Power BI creates two axes, thus allowing the datasets to be scaled differently; the left measures dollars and the right measures percentage.

对辅助 Y 轴设置格式Format the secondary Y-axis

  1. 在“可视化效果”窗格中,选择滚筒刷图标来显示格式选项。In the Visualizations pane, select the paint roller icon to display the formatting options.
  2. 通过选择向下箭头来展开 Y 轴选项。Expand the Y-Axis options by selecting the down arrow.
  3. 滚动此列表,直到找到“显示辅助对象”选项。Scroll through the list until you find the options for Show secondary. 将“显示辅助对象”从关闭切换为打开Toggle Show Secondary from Off to On.

  4. (可选)自定义两个轴。(Optional) Customize the two axes. 如果切换列轴或行轴的位置,则两个轴将交换位置。If you switch Position for either the column axis or the line axis, then the two axes switch sides.

向两个轴添加标题Add titles to both axes

对于十分复杂的可视化效果,添加轴标题会有所帮助。With a visualization this complicated, it helps to add axes titles. 标题可帮助你的同事了解可视化效果所表达的意思。Titles help your colleagues understand the story your visualization is telling.

  1. Y 轴(列)Y 轴(行)标题切换到打开Toggle Title to On for Y-Axis (Column) and the Y-Axis (Line).
  2. 样式设置为仅显示标题Set Style to Show title only.

  3. 组合图现在显示双轴,它们都具有标题。Your Combo chart now displays dual axes, both with titles.

有关详细信息,请参阅颜色格式设置、标签和轴属性的提示和技巧For more information, see Tips and tricks for color formatting, labeling, and axis properties.

注意事项和疑难解答Considerations and troubleshooting

如果报表所有者按日期类型对 X 轴进行分类,则“类型”选项将显示,并可以在连续或分类之间进行选择。If the X-axis is categorized by the report owner as a date type, the Type option will display and you can select between continuous or categorical.

后续步骤Next steps

有关 Power BI 报表中的可视化效果的详细信息More about Visualizations in Power BI reports

自定义标题、背景和图例Customize titles, backgrounds, and legends

自定义颜色和轴属性Customize colors and axis properties

Power BI - 基本概念Power BI - Basic Concepts

更多问题?More questions? 尝试参与 Power BI 社区Try the Power BI Community