This is a migrated thread and some comments may be shown as answers.

[Solved] getting the color of the line (lineseries)

5 Answers 131 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dave
Top achievements
Rank 1
Dave asked on 25 Jul 2012, 09:35 PM
I'm attempting to get the color of the line in a linegraph so i can create a legend for the graph, with the text being the same color as the line.

I have two series, but the code below returns the same color for BOTH, with the series[0] color being correct. ideas?

daschart.Series[0].DataContext = new SampleViewModel(listPulse);
               daschart.Series[1].DataContext = new SampleViewModel(listBMI);
               daschart.Height = _stack1.ActualHeight;
                
                TextBlock tb = new TextBlock();
                CategoricalStrokedSeries cs = (CategoricalStrokedSeries)daschart.Series[0];
               
                tb.Text = "Pulse";
                tb.Foreground = cs.Stroke;

                _stack1.Children.Add(tb);

                TextBlock tb2 = new TextBlock();
                CategoricalStrokedSeries cs2 = (CategoricalStrokedSeries)daschart.Series[1];

                tb2.Text = "BMI";
                tb2.Foreground = cs2.Stroke;
                daschart.Series[0].ShowLabels = true;

5 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 26 Jul 2012, 08:07 AM
Hi Dave,

 As I understand you trying to build chart legend. Unfortunately, we still do not offer built-in solution (although we are considering adding one). Currently, I can suggest to check our demo app (Teched demo) - available for download in your account download section. The app includes sample chart legend implementation.

Let us know if it helps or if you have any further questions.

All the best,
Tsvyatko
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sean
Top achievements
Rank 1
answered on 30 Oct 2012, 03:59 PM
Apologies for bumping such an old thread but I am currently trying to work through this very problem. I have downloaded the demo app and gotten the IntersectionPointTemplate and TrackInfoTemplate to work. However, the line color still does not change and I'm not quite understanding how your demo code changes the line color. Here is the code I am using to draw the series. I am also not getting an update to the legend. Any pointers would be appreciated.
private void DrawTrend(int index, string legend)
{
    DataTemplate intersectionTemplate = this.Resources["IntersectionPointTemplate"] as DataTemplate;
    DataTemplate trackInfoTemplate = this.Resources["TrackInfoTemplate"] as DataTemplate;
 
    for (int i = 0; i < index; i++)
    {
        CategoricalSeries series = Activator.CreateInstance(typeof(LineSeries)) as CategoricalSeries;
 
        series.CategoryBinding = new PropertyNameDataPointBinding("Time");
        series.ValueBinding = new PropertyNameDataPointBinding("Value");
        series.Transitions = GetTransitions();
 
        ChartTrackBallBehavior.SetIntersectionTemplate(series, intersectionTemplate);
        ChartTrackBallBehavior.SetTrackInfoTemplate(series, trackInfoTemplate);
 
        List<int> seriesData = new List<int>(15);
 
        for (int j = 0; j < 15; j++)
        {
            seriesData.Add(_random.Next(0, 100));
        }
 
        LegendItem legendItem = new LegendItem();
        legendItem.PaletteIndex = i;
        legendItem.Text = legend;
        Grid.SetColumn(legendItem, i);
        this.chartLegend.Children.Add(legendItem);
 
        series.ItemsSource = seriesData;
 
        this.radChart.Series.Add(series);
    }
}
0
Sean
Top achievements
Rank 1
answered on 30 Oct 2012, 11:18 PM
Quick update, I have gotten the legend to work but I still cannot update the color of the line. Should I be using a CategoricalStrokedSeries and setting the Stroke property to a Brush object? Can you explain how the demo sets the line color?
0
Ivaylo Gergov
Telerik team
answered on 02 Nov 2012, 12:58 PM
Hi, Sean

Thank you for using our RadControls for Windows 8!

In order to set the Stroke property of LineSeries in code behind you can use the following approach:
(this.chart.Series[0] as LineSeries).Stroke = new SolidColorBrush(Colors.Green);
You can also set the PaletteName property of the Chart and choose one of our predefined palettes.
this.chart.PaletteName = PredefinedPaletteName.DefaultDark;

I hope this information is useful. Let me know if I can assist you in some other way.

 

Regards,
Ivaylo Gergov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sean
Top achievements
Rank 1
answered on 02 Nov 2012, 08:52 PM
Ah! That's exactly what I needed. Thank you. Works like a charm now.
Tags
Chart for XAML
Asked by
Dave
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
Sean
Top achievements
Rank 1
Ivaylo Gergov
Telerik team
Share this question
or