Hi Kevin,
There is no way to conditionally color the data labels in the control and the automatic data label layout will just push the labels within the chart bounds so in this case it's probably best to use custom painting. The following code shows how to achieve this result:
[Serializable]
class NPaintCallback : INPaintCallback
{
void INPaintCallback.OnAfterPaint(NPanel panel, NPanelPaintEventArgs eventArgs)
{
NChart chart = (NChart)panel;
NBarSeries bar = (NBarSeries)chart.Series[0];
NScale2DToViewTransformation scale2View = new NScale2DToViewTransformation(chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY);
NTextStyle textStyle = new NTextStyle();
textStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Center;
NTextStyle textStyleBelow = new NTextStyle();
textStyleBelow.FillStyle = new NColorFillStyle(Color.White);
NPointF zeroPoint = new NPointF();
scale2View.Transform(new NVector2DD(0, (double)bar.Values[0]), ref zeroPoint);
for (int i = 0; i < bar.Values.Count; i++)
{
NPointF originPoint = new NPointF();
double barValue = (double)bar.Values[i];
scale2View.Transform(new NVector2DD(i, barValue), ref originPoint);
string text = barValue.ToString();
NSizeF textSize = eventArgs.Graphics.MeasureText(text, textStyle);
int offset = 10;
NPointF leftPoint = originPoint;
leftPoint.X -= offset + textSize.Width;
if (leftPoint.X > zeroPoint.X)
{
textStyle.FillStyle = new NColorFillStyle(Color.White);
eventArgs.Graphics.PaintText("100", textStyle, new NPointF(originPoint.X - offset - textSize.Width / 2.0f, originPoint.Y));
}
else
{
textStyle.FillStyle = new NColorFillStyle(Color.Black);
eventArgs.Graphics.PaintText("100", textStyle, new NPointF(originPoint.X + offset + textSize.Width / 2.0f, originPoint.Y));
}
}
}
void INPaintCallback.OnBeforePaint(NPanel panel, NPanelPaintEventArgs eventArgs)
{
}
}
private void Form1_Load(object sender, EventArgs e)
{
NChart chart = nChartControl1.Charts[0];
chart.SetPredefinedChartStyle(PredefinedChartStyle.HorizontalLeft);
NBarSeries bar = new NBarSeries();
bar.DataLabelStyle.Visible = false;
chart.PaintCallback = new NPaintCallback();
bar.Values.Add(0);
bar.Values.Add(20);
bar.Values.Add(30);
chart.Series.Add(bar);
}
Hope this helps - let us know if you meet any problems.
Best Regards,
Nevron Support Team