3

I'm developing several bar charts using chart controls in C#, one of which holds a series of ~2300 data points. In order to be able to properly display custom labels for each data point, I expanded the height of the chart to be 10000. However, it's now producing quite a large sized header and footer for the chart, as seen below: Huge Title on chart

When I set the chart to resume having a more normal height of 500, though, the title size goes back to being more reasonable. How can I manually adjust the title size?

Here's my code for the chart properties:

Chart chart = new Chart();
chart.Width = 1000;
chart.Height = 10000;
chart.BackColor = Color.FromArgb(211, 223, 240);
chart.BorderlineDashStyle = ChartDashStyle.Solid;
chart.BackGradientStyle = GradientStyle.TopBottom;
chart.BorderlineWidth = 1;
chart.Palette = ChartColorPalette.Bright;
chart.BorderlineColor = Color.FromArgb(26, 59, 105);
chart.RenderType = RenderType.BinaryStreaming;
chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
chart.AntiAliasing = AntiAliasingStyles.All;
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
chart.Titles.Add("Hit Rate");
chart.IsSoftShadows = true;

chart.ChartAreas.Add("Left");
chart.ChartAreas["Left"].AxisX.Title = "Market Area";
chart.ChartAreas["Left"].AxisY.Title = "Hit Percentage";

UPDATE: I have added this to my code...

chart.ChartAreas["Left"].InnerPlotPosition.X = 5;
chart.ChartAreas["Left"].InnerPlotPosition.Y = 0f;

which has helped somewhat. In addition, I have found that it is not the size of the title in and of itself that is causing the problem. The height of the title is actually quite normal. Instead it is all the blank space allocated to the chart above the actual graphing area.

panoptical
  • 782
  • 1
  • 8
  • 22

2 Answers2

0

Let's try this :

chart.Titles[0].Position.Auto = false;
chart.Titles[0].Position.Width = 60; //change the size you want

auto = false means you manually calculate the location. I think by default the width of the title is 50% and 50% of the chart.

Ludo

ludocal
  • 141
  • 3
  • Thanks, but this didn't work. It just moved the title into a different spot, while still leaving the blank space alone. I don't think the title is the problem, because after encapsulating the title within a border, the title seemed to occupy a normal amount of space. – panoptical Mar 19 '14 at 13:41
0

Instead of setting the height and width of the chart manually why don't you leave it to set automatically according to the content and set the below:

chart.ChartAreas[0].AxisX.Interval = 1;
chart.ChartAreas[0].AxisY.Interval = 1;

(here i'm choosing chart area 0, change it according to your code)

As you add the above code do not set the height and width of the chart. Let me know in case of issues

user3240361
  • 397
  • 1
  • 9
  • Thanks, but this didn't work either. This wound up shrinking the chart to a size too small for any of the data to be readable. – panoptical Mar 24 '14 at 13:39
  • By 2300 data points do you mean there are a total of 2300 rows and 2300 columns? – user3240361 Mar 24 '14 at 13:51
  • No, there's all of 1 column (though, because it's a bar chart, the "columns" are horizontal), but 2300 rows. That is, there is 1 number per data point that is represented on the chart. – panoptical Mar 24 '14 at 14:04
  • If 'title' seems to be problem why don't you try putting the title (as a text) and the Chart in two separate rows of HTML table. Add a table to your aspx page and have Title and Chart in two different rows aligned centrally so that the 'title size' or the blank space above the chart area will not be disturbed when you resize the chart. I did this in one of my aspx page , it looked pretty decent. – user3240361 Mar 24 '14 at 14:39