微软图表:透明度 [英] Microsoft charts: transparency

查看:92
本文介绍了微软图表:透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个透明背景的图表,因此PNG似乎是一个不错的选择.但是,当我设置透明背景时,轴标签的质量会急剧下降.我该如何解决?请参阅以下代码.就目前而言,该图表具有我想要的透明背景,但文本质量却很差.如果我注释掉两个"Color.Transparent"设置,则文本质量很好,但是背景不是透明的.

I want a chart with transparent background, and therefore PNG seems a good choice. But when I set transparent background, the quality of the axis labels falls dramatically. How do I fix this? See the following code. As it stands, the chart has a transparent background, as I want, but the text quality is atrocious. If I comment out the two "Color.Transparent" settings, then the text quality is nice, but the background is not transparent.

我如何获得透明和漂亮的文字?

How do I get transparency and nice text?

public static void Main(string[] args)
{
  Chart c = new Chart();
  c.TextAntiAliasingQuality = TextAntiAliasingQuality.High;

  Series s = new Series("Series1");
  c.Series.Clear();
  c.Series.Add(s);
  s.ChartType = SeriesChartType.Line;

  s.Color = Color.Black;

  ChartArea chartArea = new ChartArea("ChartArea1");
  c.ChartAreas.Clear();
  c.ChartAreas.Add(chartArea);

  chartArea.BackColor = Color.FromArgb(255, 255, 255);
  chartArea.BackSecondaryColor = Color.FromArgb(220, 220, 220);
  chartArea.BackGradientStyle = GradientStyle.TopBottom;

  chartArea.AxisX.LineColor = Color.Gray;
  chartArea.AxisX.LineWidth = 2;
  chartArea.AxisX.LineDashStyle = ChartDashStyle.Solid;

  chartArea.AxisY.LineColor = Color.Gray;
  chartArea.AxisY.LineWidth = 2;
  chartArea.AxisY.LineDashStyle = ChartDashStyle.Solid;

  chartArea.AxisX.MajorGrid.LineColor = Color.LightGray;
  chartArea.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;

  chartArea.AxisY.MajorGrid.LineColor = Color.LightGray;
  chartArea.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;

  c.BackColor = Color.Transparent;
  chartArea.BackColor = Color.Transparent;


  double[] x = new double[] { 1999, 2005 };
  double[] y = new double[] { 3210, 13456 };

  Axis ay = chartArea.AxisY;
  ay.Maximum = 13456;
  ay.Minimum = 3210;

  Axis ax = chartArea.AxisX;
  ax.Maximum = 2005;
  ax.Minimum = 1999;

  for (int i = 0; i < x.Length; i++)
  {
    double xvalue = x[i];
    double yvalue = y[i];
    s.Points.AddXY(xvalue, yvalue);
   }

   // Save chart-image to disk:
   c.SaveImage("chartimage.png", ChartImageFormat.Png);
}

推荐答案

将图表的 AntiAliasing 设置为 AntiAliasingStyles.Graphics ,以禁用文本的抗锯齿.

Set chart's AntiAliasing to AntiAliasingStyles.Graphics to disable the antialiasing on text.

来自此线程.

这篇关于微软图表:透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆