[英]How to adjust axis scales for datavisualization.charting after resizing a chart?
I updated a chart from essentially being 72dpi, to 300dpi. 我将图表从原来的72dpi更新为300dpi。 This is because I am using itextsharp to add an image to my pdf and the quality was poor.
这是因为我正在使用itextsharp将图像添加到pdf中,并且质量很差。 So I increased the size of the image by 3X and the image does look better, but here is the problem.
因此,我将图像的大小增加了3倍,图像看起来确实更好,但这是问题所在。
DPI has increased, but detail has become very hard to see. DPI增加了,但是细节变得很难看。
Refactored Chart Image 重构图表图像
This is how I resized my chart. 这就是我调整图表大小的方式。
private static System.Drawing.Bitmap GetChartBitmap()
{
System.Drawing.Rectangle targetBounds = new System.Drawing.Rectangle(0, 0, chart_runs.Width, chart_runs.Height);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(targetBounds.Width, targetBounds.Height);
bitmap.SetResolution(1000, 1000);
chart_runs.DrawToBitmap(bitmap, targetBounds);
bitmap.Save(@"C:\Temp\OriginalChartImage.bmp");
System.Drawing.Bitmap bitmap3 = new System.Drawing.Bitmap(1650, 990);
bitmap3.SetResolution(300, 300);
chart_runs.DrawToBitmap(bitmap3, new System.Drawing.Rectangle(0, 0, 1650, 990));
bitmap3.Save(@"C:\Temp\RefactoredChartImage.png");
//This stuff below is for my code elsewhere. Using bitmap3 to be added to pdf.
//chart_runs.DrawToBitmap(bitmap, targetBounds);
string path = System.IO.Path.GetTempPath();
bitmap1.Save(path + @"\Image.png");
return bitmap1;
}
I have looked at the Microsoft msdn examples and haven't found anything that addresses my problem. 我查看了Microsoft msdn示例,但未找到任何解决我的问题的方法。 Namely, how can I either increase the size of my labels so people can read them again.
即,如何增加标签的大小,以便人们可以再次阅读它们。 OR, is there a way for me to increase the DPI and keep the same label x and label y scale that was used in the first picture?
或者,有没有办法让我增加DPI并保持与第一张图片相同的标签x和标签y比例? That is, have a larger image and 300DPI, but scale 0 to 300 by 20's and not 5's like my refactored picture?
也就是说,有一个较大的图像和300DPI,但是将0缩放到300乘20而不是5像我重构的图片?
I would greatly appreciate any help and assistance. 我将不胜感激任何帮助和协助。
Couple different questions, with a couple different answers. 结合不同的问题和答案。 The easiest would be to change the font size of your axis labels to be bigger.
最简单的方法是将轴标签的字体大小更改为更大。 This can be done via
这可以通过
chart1.ChartAreas[0].AxisX.LabelStyle.Font = new Font...;
Without doing that, your labels won't be readable no matter what else you do, and that's just because you changed the DPI (that's exactly what changing the DPI does). 如果不这样做,则无论您做什么,标签都将不可读,这仅仅是因为您更改了DPI(这正是更改DPI所做的事情)。
If you want the labels to be displayed every 20 units on the y axis and every 15 on the x, you can use the Interval
and IntervalType
properties of the axis. 如果希望标签在y轴上每20个单位显示一次,在x轴上每15个单位显示一次,则可以使用轴的
Interval
和IntervalType
属性。 The IntervalType
is used when you have DateTime
objects being displayed: 当显示
DateTime
对象时,将使用IntervalType
:
chart1.ChartAreas[0].AxisX.Interval = 15;
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Seconds;
chart1.ChartAreas[0].AxisY.Interval = 20;
Your first link about scaling the axis is essentially zooming in or out, which is why you haven't had success. 关于缩放轴的第一个链接实质上是放大或缩小,这就是为什么您没有获得成功的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.