MSChart轴放错位置,无法显示大图 [英] MSChart axis misplaced for huge charts

查看:111
本文介绍了MSChart轴放错位置,无法显示大图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前特别遇到MSChart的问题.条形图.该图表旨在导出并保存到图像文件中,并且具有大量单独的条形图要显示,因此高度为38960px.

i'm currently running into issues with MSChart, esp. a BarChart. The chart is meant to be exported and saved into an image file and has a huge amount of seperate bars to be shown, resulting in a height of 38960px.

问题:看来,轴的标签高度是按百分比计算的,最小值为1(此后再次最小值为10px).这样标签距图表约390px ...

The problem: It seems like the height of the axis' label is calculated percentual with a minimum of 1 (and again with a minimum of 10px afterwards). This way the label is about 390px away from the chart ...

为说明问题,我将AxisX.Crossing设置为0,因此应在图表的上边框(绿线)的正下方绘制该轴.实际位置标记为红色.

To illustrate the issue, i set AxisX.Crossing = 0, so the axis should be drawn right below the upper border of the chart (green line). Actual position is marked red.

(由于我不允许发布2个以上的链接,因此我必须删除原始图像)

(as i'm not allowed to post more than 2 links, i have to remove the original image)

对于解决或解决此问题的任何帮助,我们将不胜感激.

I would appreciate any help to fix or work around this issue.

编辑:可以在此处找到一个简单的项目来演示问题/问题:

Edit: A simple project to demonstrate the question/issue can be found here: https://www.dropbox.com/s/fgyxnf4dh9v36ny/HugeMSChart.zip?dl=1

基本上:固定图表.我增加图表的高度进行演示.喜欢:

Basically: A fixed chart. I increase the height of the chart for demonstration. Like:

        // Increase height 
        chart1.Height += 100;

        // Calculate percentual value for the inner plot position for 50px (absolute)
        chart1.ChartAreas[0].InnerPlotPosition.Y = (float)((double)5000 / chart1.Height);
        chart1.ChartAreas[0].InnerPlotPosition.Height = 100 - 2 * chart1.ChartAreas[0].InnerPlotPosition.Y;

编辑2 :如评论中所述,上图并非来自示例项目.尽管如此,问题仍然存在,如新图像所示. 左图显示了一个小图表,其中轴的标签位于顶部的右侧(到顶部的距离标记为绿色). 右图显示了相同的图表,但高度约为30.000px.如您所见,轴的标签移位,因为到顶部的距离似乎与图表高度成比例.

Edit 2: As mentioned in the comments, the image above doesn't result from the sample project. Nevertheless the issue stays the same, as shown in the new image. The left images shows a small chart, where the label for the axis is situated right at the top (distance to top marked green). The right image shows the same chart but with a height of about 30.000px. As you can see, the label for the axis dislocates, as the distance to the top seems to scale with the chart height.

不幸的是,我不得不承认以前的MCVE不能涵盖整个问题(我认为是这样,但是我错了..抱歉).到目前为止,提出的解决方案适用于巨大的图表,但仅适用于有限数量的数据点.当增加数据点的数量时,轴和标签之间的边距仍然可见(即使使用IsMarginVisible = false).

Edit 3: Unfortunately I have to admit the previous MCVE would not cover the whole issue (I thought so, but I was wrong .. sorry). The solutions proposed so far work for huge charts, but only with a limited number of datapoints. When increasing the number of datapoints, the margin between the axis and the labels is still visible (even with IsMarginVisible = false).

可以在此处找到更新的MCVE(只需执行并向下滚动到最底端):

An updated MCVE may be found here (just execute and scroll down to the very bottom): https://dl.dropboxusercontent.com/u/24263856/HugeMSChart2.zip

对于旧的解决方案:当轴的交叉值上方和下方至少有一个数据点时,似乎不应用边距.但是,随着这将轴(和标签)移动到图表中,这并不是真正的解决方案.

As for the old solutions: The margin seems not to be applied when there is at least one datapoint above and below the crossing value for the axis. But as this moves the axis (and the labels) into the chart, this ain't no real solution.

推荐答案

感谢jstreet的解决方案,我发现了另一个解决方案,它允许显示具有指定长度的刻度线,并且如果未设置轴的交叉点也可以使用到图表顶部.

Thanks to the solution from jstreet, I found another one, that allows to show tick marks with a specified length and also works if crossing for the axis is not set to the top of the chart.

//Set the size of the tick mark to a fix 10px
chart1.ChartAreas[0].AxisX.MajorTickMark.Size = (float)((double)10 * 100 /(chart1.ChartAreas[0].InnerPlotPosition.Height/100 * chart1.Height));
//Remove the margin between the tick mark and the label
chart1.ChartAreas[0].AxisX.IsMarginVisible = false;

注意:特别是对于条形图(带有标签),我必须设置 AxisY.MajorTickMark.Size AxisX.IsMarginVisible 才能使其正常工作.

Note: Especially for a bar chart (as tagged), I had to set AxisY.MajorTickMark.Size and AxisX.IsMarginVisible to get it to work.

这篇关于MSChart轴放错位置,无法显示大图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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