Show value in StackingBar

Hi,

Is it possible to bind a value different than "YValue"? I mean, set for example value 50 to the bar, but show value "Eva"?

var bar = new StackingBar();
bar.DataMarker = new ChartDataMarker()
{
LabelTemplate =  = new DataTemplate(() =>
{
var label = new Label()
{
};
label.SetBinding(Label.TextProperty, "YValue", BindingMode.TwoWay, converter);
return label;
}),
ShowLabel = true
};

Thank you!

13 Replies

SP Saravana Pandian Murugan Syncfusion Team December 4, 2017 10:31 AM UTC

Hi Javier, 

Thanks for using Syncfusion products. 

You can bind different value than YValue by using LabelTemplate property of ChartDataMarker. To achieve this requirement, you can bind the XValue property which you declared in Model to the label which you return in LabelTemplate. Please find the code snippet below. 

Code Example: 

 
series1.DataMarker = new ChartDataMarker() 
            { 
                LabelTemplate = new DataTemplate(() => 
                { 
                    var label = new Label() 
                    { 
 
                    }; 
                    label.SetBinding(Label.TextProperty, "XValue"); 
                    return label; 
                }), 
           };             


We have attached sample for your reference which can be downloaded from the following location. 

 
Please check the attached sample and let us know if you need further assistance on this. 

Regards, 
Saravana Pandian M 



JA Javier December 5, 2017 03:25 PM UTC

Hi,

But what i would need is to set a text that is not in the Model, i mean, different than XValue and YValue.

Thanks.


DV Divya Venkatesan Syncfusion Team December 6, 2017 12:24 PM UTC

Hi Javier,

You can show the custom label based on the data point value using Converter. We have prepared a sample based on this.

Sample: http://www.syncfusion.com/downloads/support/forum/134859/ze/DataMarkerSample1789019779

Please check the attached sample and let us know if you need further assistance on this.

Regards,
Divya Venkatesan



JA Javier December 6, 2017 07:09 PM UTC

Hi,

I appreciate your response. However is not my goal. Maybe I have not been clear at all. I have 2 bars, the first one with value "125,2", and the second one with value "35,3". What I would need is to get the total sum (160,5) when tooltip is enabled. So this is why I was asking about showing a value different than XValue and YValue.
Attached an image to clarify it...

Thanks again.

Attachment: example_79804e56.rar


DV Divya Venkatesan Syncfusion Team December 7, 2017 11:30 AM UTC

Hi Javier,

Your requirement can be achieved by using Converter in TooltipTemplate. The values of two bars can be added in Converter by passing the whole Model to Converter. We have prepared a sample based on this.

Sample: http://www.syncfusion.com/downloads/support/forum/134859/ze/DataMarkerSample80096651

Please check the attached sample and let us know if you need further assistance on this.

Regards,
Divya Venkatesan



JA Javier December 11, 2017 10:47 AM UTC

Hi,

Is exactly what I needed. I dont know how to convert your example to c#, could you please post this code?

Thanks again.


DV Divya Venkatesan Syncfusion Team December 12, 2017 12:02 PM UTC

Hi Javier,

We have converted the sample to C#. Please download the sample from the below link.

Sample: http://www.syncfusion.com/downloads/support/forum/134859/ze/DataMarkerSample1657238641

Please let us know, if you need any further assistance on this.

Regards,
Divya Venkatesan



JA Javier December 12, 2017 01:52 PM UTC

Thank you for the example. When the program come into the converter function
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

"value" is always null. I guess the my problem is in
label.SetBinding(Label.TextProperty, ".", BindingMode.Default, converter);

but dont know why. Here is my code (exactly like yours)

salSerie.SetBinding(ColumnSeries.ItemsSourceProperty, "salPrev");
salSerie.XBindingPath = "XValue";
salSerie.YBindingPath = "YValue2";
salSerie.TooltipTemplate = new DataTemplate(() =>
{
var label = new Label()
{
BackgroundColor = Utils.Colors.FontBlue
};
label.SetBinding(Label.TextProperty, ".", BindingMode.Default, tooltipConvert);
return label;
});


Thank you!


PR Prabakaran R Syncfusion Team December 13, 2017 10:29 AM UTC

Hi Javier,


Could you please confirm us whether the binding to any property from Model class is working fine in your end?

 

label.SetBinding(Label.TextProperty, "YValue2", BindingMode.Default, tooltipConvert);


Thanks,

Prabakaran R.



JA Javier December 13, 2017 12:26 PM UTC

Hi,

Yes the binding is working fine because the chart shows the bars correctly. The problem is only related with the converter which receive null in "vallue" parameter.

Thanks!


DV Divya Venkatesan Syncfusion Team December 14, 2017 01:09 PM UTC

Hi Javier, 
 
Convert method in IValueConverter is called twice and it is returning null at first and the model object at the second time. We suspect that you have not done the null check before returning the value in Convert method. Please do a null check and let us know if you still facing any issues in this. 
 
Code snippet: 
 
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
       
            var data = value as Model; 
 
            return data?.XValue + " : " + data?.YValue2; 
       
 
Regards, 
Divya Venkatesan 



JA Javier December 14, 2017 01:34 PM UTC

ooops, sorry, that was it...

Thank you very much for your fantastic attention

Best regards


DV Divya Venkatesan Syncfusion Team December 15, 2017 04:54 PM UTC

Hi Javier,

Thanks for the update. We are glad to know that the given solution works. Please let us know if you need any further assistance.

Regards,
Divya Venkatesan


Loader.
Up arrow icon