asp.net - 如何通过 System.Web.UI.DataVisualization.Chart 使用透明度

标签 asp.net c#-4.0 webforms mschart

我正在为 ASP.NET 4.0 Web 表单上的报告设计一个简单的图表。我面临的问题是,如果我使用任何程度的透明度,图表似乎会破坏字体。考虑下面的例子:

<asp:Chart
  ID="chart" runat="server"
  Height="300px" Width="300px"
  BackColor="White"
  ImageStorageMode="UseHttpHandler">
  <Titles>
    <asp:Title Name="title" Text="Results" />
  </Titles>
  <Legends>
    <asp:Legend
      Name="Default"
      Docking="Top"
      LegendStyle="Column"
      BackColor="Transparent"
      Title="Legend"
      Font="Segoe UI, 10.25pt, style=Regular"
      TitleFont="Segoe UI, 12pt, style=Regular">
    </asp:Legend>
  </Legends>
  <Series>
    <asp:Series
      Name="Default"
      ChartType="Pie"
      CustomProperties="PieDrawingStyle=Concave,PieLabelStyle=Disabled"
      IsValueShownAsLabel="False">
      <Points>
        <asp:DataPoint Label="Argentina" YValues="5" />
        <asp:DataPoint Label="Italy" YValues="8" />
        <asp:DataPoint Label="Portugal" YValues="12" />
        <asp:DataPoint Label="China" YValues="45" />
        <asp:DataPoint Label="United States" YValues="32" />
      </Points>
    </asp:Series>
  </Series>
  <ChartAreas>
    <asp:ChartArea Name="area" BackColor="Transparent" />
  </ChartAreas>
</asp:Chart>

为了演示,我对本示例中的数据点进行了硬编码。不需要隐藏代码。我的应用程序具有正确配置的 appSettingssystem.webServer/modules 条目。请注意,图例的字体样式已明确设置为Regular

这会产生以下图表:

Chart with White Background

好的。现在来说说问题。我们要求图表位于具有渐变背景的 HTML 区域的顶部。为了避免中断渐变,我希望图表的背景区域是透明的。如果我将第四行从 BackColor="White" 更改为 BackColor="Transparent",我的所有字体都会变为粗体并失去抗锯齿功能。请参阅下文(图表位于灰色 div 中):

Chart with Transparent Background

这是图表控件的限制吗?我可以制作一个具有透明背景并仍然具有优雅字体的图表吗?还是应该考虑其他选项(例如,探索其他图表框架或修改要求)?

最佳答案

将 AntiAliasing 属性设置为 Graphics 并检查它。我已经尝试了我的曲线图及其工作原理。

<asp:Chart
  ID="chart" 
  runat="server"
  Height="300px" 
  Width="300px"
  BackColor="Transparent"
  ImageStorageMode="UseHttpHandler" 
  AntiAliasing="Graphics">

关于asp.net - 如何通过 System.Web.UI.DataVisualization.Chart 使用透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18645883/

相关文章:

asp.net - 当模式设置为 TRUE 时 jQuery UI 对话框出现问题

javascript - 使用 ajax 和 jQuery 的服务器端分页

asp.net - cassandra c# 驱动程序中的向后分页

c# - 从列表中获取月份名称和年份

asp.net - 如何在 asp.net webform 中使用我自己的购物车实现 Paypal

javascript - 单击 html 表格内的按钮时如何调用 javascript 函数?

c# - 登录 ASP.NET 网站时出现 fatal error 9001

asp.net - GIT + HTTP 跨网络失败

asp.net-mvc - 对 HttpModule 中的事件进行单元测试

c# - 将 WCF 4 中的默认 JSON 序列化程序替换为 JSON.NET