We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Adding text for series points on a bar chart

Hi,

I'm reviewing your product on C# Corner and can't figure out how to add text to the x-axis point of a bar chart to the MVCChartModel. All I see on the series in the data model is Points which only takes integers. Any ideas how to do this in the MVC version without doing the following?

(saw this in the classic ASP.NET forum)

this.simpleChart.PrimaryXAxis.TickLabelsDrawingMode = ChartAxisTickLabelDrawingMode.UserMode;
this.simpleChart.PrimaryXAxis.Labels.Clear();
this.simpleChart.PrimaryXAxis.Labels.Add(new ChartAxisLabel("0-30", Color.Black, new Font("Caliber", 8), 1, "", ChartValueType.Custom));
this.simpleChart.PrimaryXAxis.Labels.Add(new ChartAxisLabel("31-60", Color.Black, new Font("Caliber", 8), 2, "", ChartValueType.Custom));
this.simpleChart.PrimaryXAxis.Labels.Add(new ChartAxisLabel("61-90", Color.Black, new Font("Caliber", 8), 3, "", ChartValueType.Custom));




1 Reply

KD Krishnaraj D Syncfusion Team February 3, 2011 01:37 PM UTC


Hi Mike,

Thanks for your interest in Syncfusion products.

We can add text to the x-axis point of a bar chart through "ChartFormatAxisLabelEventHandler".

Refer the below code snippets.

In this code, we have formatted the x-axis point which is of type DateTime.

public ActionResult Index()
{
MVCChartModel chartModel = new MVCChartModel();
chartModel.PrimaryXAxis.DateTimeRange = new ChartDateTimeRange(dt, dtend, 1,ChartDateTimeIntervalType.Months);
chartModel.PrimaryYAxis.Range = new MinMaxInfo(50, 500, 100);
chartModel.PrimaryXAxis.DateTimeFormat = "MM-dd";
chartModel.PrimaryXAxis.ValueType = ChartValueType.DateTime;
DateTime dt = new DateTime(2011, 2, 3);
DateTime dtend = new DateTime(2011, 8, 3);
ChartSeries s1 = new ChartSeries();
s1.Points.Add(dt.AddMonths(0), 100);

ChartSeries s2 = new ChartSeries();
s2.Points.Add(dt.AddMonths(0), 150);

//Formatting the axis label text through ChartFormatAxisLabelEventHandler
chartModel.ChartFormatAxisLabel += new ChartFormatAxisLabelEventHandler(this.chartFormatAxisLabel);

. . . . . . .
. . . . . . .

return View();
}



//handling the chart format axis label event
void chartFormatAxisLabel(object sender, ChartFormatAxisLabelEventArgs e)
{
if (e.AxisOrientation == ChartOrientation.Horizontal)
{
if (e.Label == "02-03")
e.Label = "Feb";
else if (e.Label == "03-03")
e.Label = "Mar";
else if (e.Label == "04-03")
e.Label = "Apr";
else if (e.Label == "05-03")
e.Label = "May";
else if (e.Label == "06-03")
e.Label = "Jun";
else if (e.Label == "07-03")
e.Label = "Jul";

e.Handled = true;
}
}


Please let us know if you have any queries.

Regards,
Krishnaraj D


Loader.
Live Chat Icon For mobile
Up arrow icon