简体   繁体   English

调整图表大小后如何为datavisualization.charting调整轴刻度?

[英]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增加了,但是细节变得很难看。

Original Chart Image 原始图表图像

原始图片

Refactored Chart Image 重构图表图像 在此处输入图片说明

Code

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像我重构的图片?

Attempts to fix 尝试修复

  • Scaling the axis? 缩放轴? See here . 这里 I don't think this is working right. 我认为这行不通。 Not much success here. 在这里没有太大的成功。
  • Been trying to find a way in Chart class to see if there is a way to specify strict scales. 试图在Chart类中找到一种方法来查看是否有一种方法来指定严格的比例尺。 (20 on y scale vs 15 seconds on x scale). (y比例为20,x比例为15秒)。
  • Most online resources are pleased just to increase the scale of the picture and walk away. 大多数在线资源很高兴能增加图片的比例并走开。 And things like this here. 像这样的事情

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个单位显示一次,则可以使用轴的IntervalIntervalType属性。 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.

相关问题 轴绘制点并阻止DataVisualization.Charting中的选择 - Axis drawing over point and preventing selection in DataVisualization.Charting C#添加图表错误DataVisualization.Charting-Visual Studio - C# add chart error DataVisualization.Charting - Visual Studio DataVisualization.Charting空点 - DataVisualization.Charting Empty point 在DataVisualization中对齐标签 - Align labels in DataVisualization.Charting effectively C#,DataVisualization.Charting:将自定义标签分配给轴上的值 - C#, DataVisualization.Charting: assign custom labels to values on axes 如何使用Web.UI.DataVisualization.Charting绘制图表? - How to chart using Web.UI.DataVisualization.Charting? 是否可以以十六进制显示DataVisualization.Charting.Chart的x轴值? - Is it possible to display the x-axis values of the DataVisualization.Charting.Chart in hexadecimal? 用工作日标记 System.Windows.Forms.DataVisualization.Charting 图表中的 X 轴 - label the X axis in a System.Windows.Forms.DataVisualization.Charting chart with weekdays DataVisualization.Charting.Axis.GetLinearPosition()的NullReferenceException - NullReferenceException from DataVisualization.Charting.Axis.GetLinearPosition() 如何在X轴上为System.Windows.Forms.DataVisualization.Charting设置DateTime范围? - How do you set DateTime range on X axis for System.Windows.Forms.DataVisualization.Charting?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM