如何解决C# Chart,如何使文本不太像素化且没有边框?
我正在使用 .NET 库来制作图表。我的问题是 XY 轴的标签/标题非常像素化,它们似乎有一个黑色边框,我不知道如何删除。
另一个问题是在图表上,有黑色轴从图表中延伸到黑色标签,我不知道如何将它们设置为灰色。
我还为所有标签使用了一种名为 Inter 的字体,我认为使用该字体不会使标签具有黑色边框。
图表图像:
感谢您的帮助!
代码:
PrivateFontCollection pfc = new PrivateFontCollection();
int fontLength = RestocksDiscordBot.Properties.Resources.Inter_Bold.Length;
byte[] fontdata = RestocksDiscordBot.Properties.Resources.Inter_Bold;
System.IntPtr data = Marshal.AllocCoTaskMem(fontLength);
Marshal.Copy(fontdata,data,fontLength);
pfc.AddMemoryFont(data,fontLength);
Legend legend = new Legend();
Random random = new Random();
Chart chart = new Chart();
chart.Legends.Add(legend);
chart.Width = 600;
chart.Height = 400;
chart.BackColor = System.Drawing.Color.Transparent;
chart.AntiAliasing = AntiAliasingStyles.Graphics;
chart.BorderlineColor = System.Drawing.Color.White;
chart.BorderlineWidth = 2;
chart.Series.Clear();
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.High;
legend.TitleFont = new Font(pfc.Families[0],14f);
legend.Title = "Prices";
var chartArea = chart.ChartAreas.Add("Sizes");
chartArea.AxisX.Title = "Dates";
chartArea.AxisX.TitleFont = new Font(pfc.Families[0],16f);
chartArea.AxisX.TitleForeColor = System.Drawing.Color.White;
chartArea.AxisY.Title = "Prices";
chartArea.AxisY.TitleFont = new Font(pfc.Families[0],16f);
chartArea.AxisY.TitleForeColor = System.Drawing.Color.White;
chartArea.AxisX.MinorGrid.LineColor = System.Drawing.Color.Gray;
chartArea.AxisX.MinorGrid.LineWidth = 2;
chartArea.AxisY.MinorGrid.LineColor = System.Drawing.Color.Gray;
chartArea.AxisY.MinorGrid.LineWidth = 2;
chartArea.AxisX.LineColor = System.Drawing.Color.Gray;
chartArea.AxisY.LineColor = System.Drawing.Color.Gray;
chartArea.AxisX.MajorGrid.LineColor = System.Drawing.Color.Gray;
chartArea.AxisX.MajorGrid.LineWidth = 2;
chartArea.AxisY.MajorGrid.LineColor = System.Drawing.Color.Gray;
chartArea.AxisY.MajorGrid.LineWidth = 2;
chartArea.AxisX.LabelStyle.ForeColor = System.Drawing.Color.White;
chartArea.AxisY.LabelStyle.ForeColor = System.Drawing.Color.White;
chartArea.AxisX.LabelStyle.Font = new Font(pfc.Families[0],16f);
chartArea.AxisY.LabelStyle.Font = new Font(pfc.Families[0],14f);
chartArea.AxisX.Interval = 2;
chartArea.AxisY.Interval = 20;
chartArea.AxisY.Minimum = 80;
chartArea.BackColor = System.Drawing.Color.Transparent;
chartArea.BorderColor = System.Drawing.Color.White;
chartArea.BorderWidth = 2;
Series chartSeries = chart.Series.Add("38.5");
chartSeries.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
chartSeries.XValueType = ChartValueType.String;
chartSeries.BorderWidth = 5;
chartSeries.BorderColor = System.Drawing.Color.White;
chartSeries.LabelForeColor = System.Drawing.Color.White;
chartSeries.Color = System.Drawing.ColorTranslator.FromHtml("#7142ff");
chartSeries.MarkerSize = 15;
List<Tuple<string,int>> sales = new List<Tuple<string,int>>();
sales.Add(new Tuple<string,int>(null,random.Next(100,200)));
sales.Add(new Tuple<string,int>(DateTime.Now.AddDays(1).ToString("MMM dd"),int>(DateTime.Now.AddDays(3).ToString("MMM dd"),int>(DateTime.Now.AddDays(5).ToString("MMM dd"),200)));
foreach (var sale in sales)
{
if (sale.Item1 == null)
chartSeries.Points.AddY(sale.Item2);
else
chartSeries.Points.AddXY(sale.Item1,sale.Item2);
}
string imageNameAndPath = Logic.programPath + "/chart.png";
chart.SaveImage(imageNameAndPath,ChartImageFormat.Png);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。