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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

LineSeries not displaying value

Thread ID:

Created:

Updated:

Platform:

Replies:

151242 Feb 5,2020 02:26 AM UTC Feb 6,2020 01:13 PM UTC Xamarin.Forms 3
loading
Tags: SfChart
dev clinicea
Asked On February 5, 2020 02:26 AM UTC

Hi,
I am using a line series on a sfchart. I am binding a collection i.e. List<ChartData> to the ItemsSource. The line series appears fine when there are multiple items in the collection. But if there is only 1 item in the collection, the chart shows nothing.

How do I make a single item also show in a lineseries?

Tx

Hemalatha Marikumar [Syncfusion]
Replied On February 5, 2020 06:32 AM UTC

Hi Dev clinicea, 
 
Greetings from Syncfusion. 
 
Query: How do I make a single item also show in a lineseries? 
 
We would like to let you know that a line segment must require at least two data points to be plotted. If your requirement “Visibility of a single data point with LineSeries” can be achieved by using DataMarker in your sample as per the code snippet below. 
 
Code Snippet [XAML] MainPage 
<chart:SfChart x:Name="chart1" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> 
        <chart:SfChart.PrimaryAxis> 
            <chart:NumericalAxis RangePadding="Additional" /> 
        </chart:SfChart.PrimaryAxis> 
        <chart:SfChart.SecondaryAxis> 
            <chart:NumericalAxis RangePadding="Additional"/> 
        </chart:SfChart.SecondaryAxis> 
        <chart:LineSeries   ItemsSource="{Binding LineData1}" 
                            XBindingPath="XVal"  
                            YBindingPath="YValue">         
            <chart:LineSeries.DataMarker> 
                <chart:ChartDataMarker  
                    ShowLabel="True"  
                    ShowMarker="True"/> 
            </chart:LineSeries.DataMarker> 
        </chart:LineSeries> 
 </chart:SfChart> 
 
Code Snippet [C#] [ViewModel] 
public class LineSeriesViewModel 
    { 
        public ObservableCollection<ChartModel> LineData1 { get; set; } 
        public LineSeriesViewModel() 
        { 
            LineData1 = new ObservableCollection<ChartModel> 
            { 
                new ChartModel(7, 45), 
            }; 
        } 
    } 
 
Output: 
 
 
Regards, 
Hemalatha M. 
 
 
 
 
 


dev clinicea
Replied On February 5, 2020 10:28 AM UTC

I tried it, but it still does not work :(. here is my code, screen is blank. Can you suggest what might be wrong?

            chart = new SfChart();
            chart.Title.Text = "sample title";
            chart.VerticalOptions = LayoutOptions.FillAndExpand;
           
            //xaxis
            //https://www.syncfusion.com/forums/131901/date-format-datetimeaxis
            DateTimeAxis dateTimeAxis = new DateTimeAxis();
            dateTimeAxis.Title.Text = "";
            dateTimeAxis.LabelStyle.LabelFormat = "dd-MMM";
            dateTimeAxis.LabelRotationAngle = 90;
            chart.PrimaryAxis = dateTimeAxis;
            chart.PrimaryAxis.IsVisible = true;
         


            //Initializing secondary Axis
            NumericalAxis secondaryAxis = new NumericalAxis();
            secondaryAxis.RangePadding = NumericalPadding.Additional;
            chart.SecondaryAxis = secondaryAxis;
            chart.SecondaryAxis.IsVisible = true;





            //Initializing series
            series = new LineSeries();
            series.XBindingPath = "VitalID";
            series.YBindingPath = "VitalValueNum";


            series.DataMarker = new ChartDataMarker();
            //both showmarker and showlabel required to show a single data point
            series.DataMarker.ShowMarker = true;
            series.DataMarker.ShowLabel = true;
            series.DataMarker.LabelStyle.LabelPosition = DataMarkerLabelPosition.Outer;
            series.DataMarker.LabelStyle.TextColor = Styles.ColorBlack;    
            series.DataMarker.LabelStyle.BorderThickness = 0;
            series.DataMarker.LabelStyle.BackgroundColor = Styles.ColorWhite;
            series.EnableTooltip = true;
           
            chart.Series.Add(series);

Attachment: Screenshot_1580898295_1274cb19.zip

Hemalatha Marikumar [Syncfusion]
Replied On February 6, 2020 01:13 PM UTC

Hi Dev clinicea, 
  
We have analyzed the provided code snippet and screenshot, we noticed that range of both chart axes has been changed and set based on the single data point. And also we have found that Additional RangePadding is not set for primary axis alone. So, to avoid this issue, please set RangePadding to the primary DateTimeAxis as per in below code snippet. 
 
C#: 
 
chart = new SfChart() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand}; 
            
DateTimeAxis dateTimeAxis = new DateTimeAxis(); 
dateTimeAxis.LabelStyle.LabelFormat = "dd-MMM"; 
dateTimeAxis.LabelRotationAngle = 90; 
dateTimeAxis.RangePadding = DateTimeRangePadding.Additional; 
  
NumericalAxis secondaryAxis = new NumericalAxis() 
{ 
    RangePadding = NumericalPadding.Additional, 
}; 
  
chart.PrimaryAxis = dateTimeAxis; 
chart.SecondaryAxis = secondaryAxis; 
            
LineSeries lineSeries = new LineSeries() 
{ 
    ItemsSource = viewModel.DateData, 
    XBindingPath = "Date", 
    YBindingPath = "YValue", 
}; 
  
lineSeries.DataMarker = new ChartDataMarker() 
{ 
    ShowLabel = true, 
    ShowMarker = true, 
    UseSeriesPalette = true, 
    MarkerType = DataMarkerType.Ellipse, 
    MarkerHeight = 10, 
    MarkerWidth = 10, 
    LabelStyle = new DataMarkerLabelStyle() 
    { 
        BackgroundColor = Color.Transparent, 
        TextColor = Color.Black, 
        LabelPosition = DataMarkerLabelPosition.Auto, //This is default value 
    }, 
}; 
  
chart.Series.Add(lineSeries); 
 
  
 
Note: You have set the Position of DataMarker as outer, it may lead to have a chance of getting the reported issue. So, please set as Auto (default value). 
 
Please let us know if you need any further assistance on this. 
 
Regards,
Hemalatha M. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon