Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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 ...

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.

(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;

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.

enter image description here

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).

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
140 views
Welcome To Ask or Share your Answers For Others

1 Answer

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;

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...