public partial class mschart : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = CreatData();
#region
Chart1.DataSource = dt;
Chart1.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Column;
Chart1.Series[0].XValueMember = "Language";
Chart1.Series[0].YValueMembers = "Count";
Chart1.ChartAreas["ChartArea1"].AxisX.Title = "language";
Chart1.ChartAreas["ChartArea1"].AxisX.TitleAlignment = StringAlignment.Far;
Chart1.ChartAreas["ChartArea1"].AxisY.Title = "count";
Chart1.ChartAreas["ChartArea1"].AxisY.TitleAlignment =StringAlignment.Far;//
Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; //Set the interval of the AxisX as 1;
Chart1.ChartAreas["ChartArea1"].AxisX.IntervalOffset = 1;// Set the AxisX Intervaloffset as 1
Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsStaggered = true; //Set whether to interleave the display, such as when the data is too large, divide it into two lines to display.
#endregion
}
DataTable CreatData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Language", typeof(string ));
dt.Columns.Add("Count", typeof(string));
string[] n = new string[] { "1", "2","3","4","5","6","7","8","9","10" };
// int[] n = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 10 };
string[] c = new string[] { null, "2", null, "5",null,"7",null,null,null,null,};
for (int i = 0; i < n.Length; i++)
{
DataRow dr = dt.NewRow();
dr["Language"] = n[i];
dr["Count"] = c[i];
dt.Rows.Add(dr);
}
return dt;
}
}
Result:
Best Regards,
Brando
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
All-Star
52673 Points
15720 Posts
How Show Odd values Axist Labels in MS Chart
Nov 21, 2018 12:45 AM|oned_gk|LINK
I Have use ms chart control in my web form
xvalues are 1,2,3,4,5,6,7,8,9,10 (int)
xaxist label display as 0,1,2,3,4,5,6,7,8,9,10,11
I dont want to show 0 and 11 labels, but i have not get it yet
To remove 0 and 11, i change the x value to string
xvalues are '1','2','3','4','5','6','7','8','9','10' (varchar), now the chart don't show 0 and 11 anymore
But now i have new issue. If x value more than 9 it show event labels only
xaxist label display as 2,4,6,8,10 I want 1,2,3,4,5,6,7,8,9,10
How to overcome this problem?
Suwandi - Non Graduate Programmer
Star
9831 Points
3120 Posts
Re: How Show Odd values Axist Labels in MS Chart
Nov 22, 2018 08:58 AM|Brando ZWZ|LINK
Hi oned_gk,
According to your description, I suggest you could try to set the AxisX.Interval, AxisX.Intervaloffset,AxisX.LabelStyle.IsStaggered property, then it will work well.
More details, you could refer to below codes:
ASPX:
Code-behind:
Result:
Best Regards,
Brando
All-Star
52673 Points
15720 Posts
Re: How Show Odd values Axist Labels in MS Chart
Nov 23, 2018 01:06 AM|oned_gk|LINK
Your solution have pointing me, thank you very much
I have set this properties to fix
Suwandi - Non Graduate Programmer