2
votes

I am new to dev-express and I was trying to create a Line chart with below data:

enter image description here

In x-axis is the years and y-axis has the population And to plot for all the 3 countries there will be three series.

I have successfully created the chart but the year shows somewhat like this: enter image description here

if you see the x-axis it is coming like in decimals although in database year is in YEAR(Mysql)

I tried using

diagram.AxisX.VisualRange.Auto = false;
diagram.AxisX.VisualRange.AutoSideMargins = true;
diagram.AxisX.VisualRange.MinValue = 2000;
diagram.AxisX.VisualRange.MaxValue = 2010;
diagram.AxisX.WholeRange.MinValue = 1990;
diagram.AxisX.WholeRange.MaxValue = 2014;

Also one more problem I was having I tried using WholeRange.MaxValueInternal and VisualRange.MaxValueInternal But got below error: enter image description here

Also I do know the difference between VisualRange and wholerange but i did not get the importance of MaxValueInternal except that it should be set to double when series' argumentscaletype is datetime or qualitative but how does it effects the series? what is diffrence if we dont use it at all or use it on chart?

1

1 Answers

2
votes

I think you are confused between MaxValueInternal and MaxValueInterval. You cannot set a value to VisualRange.MaxValueInternal property because this property is only have a getter declared.
You can use AxisX.NumericScaleOptions property to set an interval. Just set NumericScaleOptions.GridAlignment property to NumericGridAlignment.Custom and set NumericScaleOptions.CustomGridAlignment property to YourIntervalValue / 2.
Here is example:

const double interval = 1;

var table = new DataTable();

table.Columns.Add("id", typeof(int));
table.Columns.Add("Country", typeof(string));
table.Columns.Add("Year", typeof(int));
table.Columns.Add("Population_millions", typeof(int));

table.Rows.Add(1, "Europe", 2000, 4000);
table.Rows.Add(2, "America", 2000, 7000);
table.Rows.Add(3, "Africa", 2000, 1000);
table.Rows.Add(4, "Africa", 2005, 2000);
table.Rows.Add(5, "Europe", 2005, 9000);
table.Rows.Add(6, "America", 2005, 6000);
table.Rows.Add(7, "America", 2007, 3000);
table.Rows.Add(8, "Europe", 2007, 1900);
table.Rows.Add(9, "Africa", 2007, 1500);

var chart = new ChartControl();

chart.DataSource = table;
chart.SeriesDataMember = "Country";
chart.BindToData(ViewType.Line, table, "Country", "Year", new string[] { "Population_millions" });

var diagram = (XYDiagram)chart.Diagram;

diagram.AxisX.NumericScaleOptions.GridAlignment = NumericGridAlignment.Custom;
diagram.AxisX.NumericScaleOptions.CustomGridAlignment = interval / 2;

diagram.AxisX.WholeRange.MinValue = 1990;
diagram.AxisX.WholeRange.MaxValue = 2014;
diagram.AxisX.VisualRange.Auto = false;
diagram.AxisX.VisualRange.AutoSideMargins = true;
diagram.AxisX.VisualRange.MinValue = 2000;
diagram.AxisX.VisualRange.MaxValue = 2010;

diagram.EnableAxisXScrolling = true;
diagram.EnableAxisXZooming = true;

chart.Dock = DockStyle.Fill;

Controls.Add(chart);

And here is result of example:
Result