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

Multiple XAxis

Hi,

I need to create multiple XAxis depending on XAxis header and OpposedPosition.
But when I create new CharAxis and assign to serie.XAxis, it is not creating the XBindPath values labels.
It is creating the labels with 0,1,2.... but when I changed the labelmode from default to Datasource and assign datasource it is also causing problems.

Please help me how to create the multiple XAxis and it should automatically pick label from XPathBindind values. I am not using the WPF designer. I am creating chart control using C#.

Thanks,
Sadaqat

1 Reply

VK Vinoth Kumar J Syncfusion Team December 20, 2012 05:36 AM UTC

Hi Sadaqat,

The LabelSource of ChartAxis should be collection of Double, String or DateTime. It should not be any other class. So you need to calculate the Labels for Axis manually as shown in below code snippet.

Code Snippet(C#):
            List<double> _labelSource = new List<double>();
            for (int i = 0; i < _viewModel.DataCollection.Count; i++)
            {
                _labelSource.Add(_viewModel.DataCollection[i].XData);
            }

            ChartSeries series = new ChartSeries() {Type=ChartTypes.Line, DataSource = _viewModel.DataCollection, BindingPathX = "XData", BindingPathsY = new List<String> {"YData"} };
            series.XAxis = new ChartAxis() { IsAutoSetRange = true,RangeCalculationMode=RangeCalculationMode.ConsistentAcrossChartTypes,RangePadding=ChartRangePaddingType.None};

            ChartArea area = new ChartArea();
            area.PrimaryAxis = new ChartAxis() { IsAutoSetRange=false,Range=new DoubleRange(_labelSource[0],_labelSource[_labelSource.Count-1]),LabelsMode = ChartAxisLabelsMode.DataSource, LabelsSource = _labelSource };
            area.SecondaryAxis = new ChartAxis() { IsAutoSetRange = true };
            area.Series.Add(series);

            Chart chart = new Chart();
            chart.Areas.Add(area);

We have prepared a sample based on this. Please find the attached sample.
If you still facing any issues, please revert to us by modifying the sample. This would be more helpful to assist you better.

Sample:

Please let us know if you have any queries.

Thanks,
Vinoth Kumar J


MultipleXAxis_176b88a2.zip

Loader.
Live Chat Icon For mobile
Up arrow icon