-1

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.

DanielT
  • 81
  • 9
  • @DanielT, are you trying to say the tick for 0.4KB is supposed to be where you indicate a green line? – Baddack Jun 03 '16 at 23:40
  • Are your x-values numeric? (Use the debugger to test!) How are the values added? - Btw: Winforms controls have an inner size limit of 32k pixels so I would not be surprised to see problems with such a huge chart.. – TaW Jun 04 '16 at 15:29
  • @jstreet: Uploaded a sample project. – DanielT Jun 06 '16 at 12:41
  • @Baddack: No, not the tick. It's about the whole label of the axis (0.4KB ... 0.6KB .. [and so on]). It should be situated at a fixed y-position. – DanielT Jun 06 '16 at 12:42
  • @TaW: 1. (in reference to the sample project) All XValues are 0. 2. The limitation is 64k (2^16). Nevertheless: The issue occurs with every size, also smaller ones. – DanielT Jun 06 '16 at 13:01
  • _All XValues are 0_ I thought so. So you don't add the x-values as numbers but as strings? – TaW Jun 06 '16 at 14:07
  • @jstreet: Thank you for your hint about the XY Problem. I don't think I'm falling for it, as I have no (proposed) solution right now. – DanielT Jun 06 '16 at 14:22
  • @TaW: As for the sample project, i didn't add them at all. I just added the yValues for some datapoints in one series in the designer. The chart/the designer chose the caption. – DanielT Jun 06 '16 at 14:24
  • @jstreet: Sorry, I mixed AxisX and AxisY (I set them both to 0, as it was just to illustrate the issue. The axis' label is actually supposed to be under the chart but doesn't fit the image in that scenario and thus becomes invisible). – DanielT Jun 06 '16 at 14:31
  • @jstreet: The sample project is as MCVE as it could be. You could actually place a Chart on the designer and set its height to 30000. You have the issue right away. – DanielT Jun 06 '16 at 14:33
  • @jstreet: Again, thanks for your help. I've updated the question a few minutes ago, replacing the original image with images from the sample project. They should illustrate the issue and correspond to the posted code. All I actually want to achieve is a fixed distance (in pixel) between the top border of the chart (or the chart area, doesn't matter) and the label of the axis below. – DanielT Jun 06 '16 at 14:40
  • @jstreet: Yes you're right. You have to push the button (a few times to make it even bigger). If you want to I will upload an updated project where the height is set to 30000 as default. (p.s. I'm sorry if I sound a little rude, this isn't intended ..) – DanielT Jun 06 '16 at 14:44
  • If there are no valid (numeric or datetime) x-values some things like setting a range misbehave.. - `chart1.ChartAreas[0].InnerPlotPosition.Y = (float)((double)5000 / chart1.Height);` This make the IPP depend directly on the `chart.Height` without taking the `ChartArea.Position.Height` into account! Are you doing this (manipulating the IPP size) in your real project as well? – TaW Jun 06 '16 at 15:27
  • @jstreet: I don't think so. He talks about the vertical position of the axis; look at where the labels run, in the middle, not at the top where he expects them.. – TaW Jun 06 '16 at 15:30
  • 1
    You are right! Wow, there is always somethin new to learn about charts :-) – TaW Jun 06 '16 at 15:35
  • @jstreet: Thanks for the effort, great work! ;-) – DanielT Jun 06 '16 at 21:16

1 Answers1

1

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.

DanielT
  • 81
  • 9