Reputation: 39
My question is pretty straightforward, but I have a feeling the answer is a little more involved:
I'm trying to get the labels on this chart set up such that the first date will be to the left of the bar and the last date will be to the right:
Each bar is actually made of a point representing the whole timespan (drawn as a border with white inside color) and a point representing the % completed (drawn as the solid fill in those borders).
What I've got accomplished so far is done using Point CustomProperties:
Chart1.Series[s].Points[0].Label = gsvPhaseList[0].EndDate.Value.ToString("M/dd");
Chart1.Series[s].Points[0].SetCustomProperty("BarLabelStyle", "Outside");
Chart1.Series[s].Points[1].Label = gsvPhaseList[0].StartDate.Value.ToString("M/dd");
Chart1.Series[s].Points[1].SetCustomProperty("BarLabelStyle", "Left");
My problem is that there doesn't seem to be a way to say "Left & Outside".
My next step is to add a hook to the Paint event on the chart so I can actually get the label's position and shift to the left (I hope), but I wanted to make sure there wasn't something simple I'm missing first. Any ideas?
Upvotes: 2
Views: 4561
Reputation: 54433
Your Chart displays RangeBars. You can fake the Outside-Left position by adding one extra DataPoint to the left of each Point.
You need to make it wide enough to hold the Label and you should keep it a little bit to the left of the real point, so the Label won't touch the side.
Make its Color = Color.Transparent and your Labels will show to the left and right.
Here is a piece of code that does the adornment for all Series in a Chart:
// just a few test data in Series S1 & S2..
S1.Points.AddXY(1, 13, 14.5); // the dummy point
S1.Points.AddXY(1, 15,22);
S2.Points.AddXY(1, 7,8.5); // 2nd dummy
S2.Points.AddXY(1, 9,13);
// set the labels
foreach (Series S in chart1.Series)
for (int i = 0; i < S.Points.Count; i+=2 )
{
DataPoint pt0 = S.Points[i];
DataPoint pt1 = S.Points[i + 1];
pt0.Color = Color.Transparent;
pt0.SetCustomProperty("BarLabelStyle", "Right");
pt0.Label = pt1.YValues[0] + " ";
pt1.SetCustomProperty("BarLabelStyle", "Outside");
pt1.Label = " " + pt1.YValues[1];
}
You could write code to actually add those extra label points automatically, too..
Upvotes: 3