Pre loader

Move settings from Legend to separate menu

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered Closed
1
0

Hello.
I’d checked examples from your Demo ‘SciChart.Examples.Demo’ and looks like the example “SciChart.Examples.Examples.CreateRealtimeChart.UsingSeriesValueModifier” is applicable for me because I need functionality like this.

But as I understand Legend as LegendModifier component is a part of chart and it ‘know’ about chart data and can manipulate layout of it. In my application I want to have chart settings not in chart layout but in separate part of application. Can I bind chart settings with my custom controls? At start I want to set visibility for chart series which created in code

        private XyDataSeries<double, double> _lineDataDiameter1;
        private XyDataSeries<double, double> _lineDataDiameter2;
        private XyDataSeries<double, double> _lineDataCovering1;
        private XyDataSeries<double, double> _lineDataCovering2;
        private XyDataSeries<double, double> _lineDataCovering3;

private void InitCharts()
    { // TODO names and color maybe make as settings
        _lineDataDiameter1 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_DIAMETER_1, LineColor = Colors.OrangeRed, ChartStyle = CHART_LINE_STYLE, LineThickness = CHART_LINE_THICKNESS });
        _lineDataDiameter2 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_DIAMETER_2, LineColor = Colors.BlueViolet, ChartStyle = CHART_LINE_STYLE, LineThickness = CHART_LINE_THICKNESS });
        _lineDataCovering1 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_COVERING_1, LineColor = Colors.LimeGreen, ChartStyle = CHART_LINE_STYLE, LineThickness = CHART_LINE_THICKNESS });
        _lineDataCovering2 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_COVERING_2, LineColor = Colors.DeepSkyBlue, ChartStyle = CHART_LINE_STYLE, LineThickness = CHART_LINE_THICKNESS });
        _lineDataCovering3 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_COVERING_3, LineColor = Colors.White, ChartStyle = CHART_LINE_STYLE, LineThickness = CHART_LINE_THICKNESS });
    }

    private XyDataSeries<double, double> InitChart(InitChartRequest request)
    {
        XyDataSeries<double, double> lineData = new()
        {
            SeriesName = request.ChartName,
        };

        RenderableSeries.Add(new LineRenderableSeriesViewModel()
        {
            StrokeThickness = request.LineThickness,
            Stroke = request.LineColor,
            DataSeries = lineData,
            StyleKey = request.ChartStyle,
        });

        return lineData;
    }

And additional little question. How can I make CursorModifier visible or not?

            <s:SciChartSurface.ChartModifier>
                <s:ModifierGroup>
                    <s:SeriesValueModifier/>
                    <s:CursorModifier/>
                </s:ModifierGroup>
            </s:SciChartSurface.ChartModifier>

Even if I make it like this

                <s:SciChartSurface.ChartModifier>
                    <s:ModifierGroup>
                        <s:SeriesValueModifier/>
                        <s:CursorModifier Visibility="Hidden"/>
                    </s:ModifierGroup>
                </s:SciChartSurface.ChartModifier>

I see it

Version
8.1.0.27856
Images
  • You must to post comments
0
0

Hi Fedor,

To disable (hide, or set invisible) the CursorModifier, set CursorModifier.IsEnabled = false. This will disable it and remove all visuals from the chart for this modifier.

For separating the Legend control: In the LegendModifier documentation we have a section on how to separate the SciChartLegend control (the visual for the LegendModifier) and the LegendModifier itself – the view model for the legend.

Please see the section titled “Binding LegendModifier.LegendData to SciChartLegend”

Alternatively – Binding LegendModifier.LegendData to SciChartLegend

You can alternatively bind LegendModifier.LegendData to a
SciChartLegend and place anywhere in your application. You can also
bind to an LegendModifier.LegendData to an ItemsControl.ItemsSource
and template it as you wish.

<s:SciChartSurface x:Name="sciChart" s:ThemeManager.Theme="Chrome">
  
      
  
      
      <s:SciChartSurface.ChartModifier>
          <s:ModifierGroup>
              <s:LegendModifier x:Name="legendModifier" GetLegendDataFor="AllSeries" ShowLegend="False"/>
          </s:ModifierGroup>
      </s:SciChartSurface.ChartModifier>
  
  </s:SciChartSurface>
  
  
  <s:SciChartLegend x:Name="legendControl"
     s:ThemeManager.Theme="Chrome"
     Margin="23,23"
     ScrollViewer.HorizontalScrollBarVisibility="Auto"
     ScrollViewer.VerticalScrollBarVisibility="Auto"
     LegendData="{Binding LegendData, ElementName=legendModifier, Mode=OneWay}"
     ShowVisibilityCheckboxes="True" />
  

This technique allows you to place a SciChartLegend control anywhere in your application and then bind it to a LegendModifier.LegendData property. However this isn’t the only option.

It’s also possible to create your own custom ItemsControl and bind ItemsControl.ItemSource to LegendModifier.LegendData.

The LegendData property is described here in the docs. This is a type ChartDataObject which has an ObservableCollection. Each SeriesInfo is a viewmodel describing a series

For more info about the SeriesInfo type – see the documentation page SeriesInfo – the ViewModels for Tooltips and Legends

Best regards,
Andrew

  • You must to post comments
0
0

Hello.
As I understand It is applies if LegendModifier and SciChartLegend in the same file and same namescope. Because for ElementName=legendModifier name ‘legendModifier’ is visible only from same namescope. But in my case I have chart in one of XAML UserControls and place for settings (and chart legend) in another one XAML.

ChartSettings.xaml

Chart.xaml

I used MVVM in my application and maybe I can create class for LegendModifier.LegendData somewhere in VM’s code and bind it to LegendModifier.LegendData and ModifierGroup.LegendModifier.LegendData both? Is it good solution or it possible to make better? And it’s not very good to use “ElementName=” for MVVM as I see. Now I write this code for VM

private ChartDataObject _legendData;
public ChartDataObject LegendData
{
    get { return _legendData; }
    set
    {
        SetProperty(ref _legendData, value, nameof(LegendData));
    }
}

private void InitCharts()
{ // TODO names and color maybe make as settings
    _renderableSeries = new ObservableCollection<IRenderableSeriesViewModel>();
    _annotations = new ObservableCollection<IAnnotationViewModel>();

    _isMarkerPhase = false;

    _lineDataDiameter1 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_DIAMETER_1, LineColor = Colors.OrangeRed, ChartStyle = CHART_LINE_STYLE });
    _lineDataDiameter2 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_DIAMETER_2, LineColor = Colors.BlueViolet, ChartStyle = CHART_LINE_STYLE });
    _lineDataCovering1 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_COVERING_1, LineColor = Colors.LimeGreen, ChartStyle = CHART_LINE_STYLE });
    _lineDataCovering2 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_COVERING_2, LineColor = Colors.DeepSkyBlue, ChartStyle = CHART_LINE_STYLE });
    _lineDataCovering3 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_COVERING_3, LineColor = Colors.White, ChartStyle = CHART_LINE_STYLE });

    _legendData = new ChartDataObject() { };
}

This is part of code for Chart.xaml (it is UserControl with SciChartSurface)

            <s:SciChartSurface.ChartModifier>
                <s:ModifierGroup>
                    <s:SeriesValueModifier />
                    <s:CursorModifier IsEnabled="{Binding IsShowValuesCursor}" />
                    <s:LegendModifier x:Name="SciChartLegendModifier" GetLegendDataFor="AllSeries" ShowLegend="False" LegendData="{Binding LegendData}" />
                </s:ModifierGroup>
            </s:SciChartSurface.ChartModifier>

And this is part of code for ChartSettings.xaml (it is UserControl with any settings. I want to place chart legend here)

    <Border DockPanel.Dock="Top" Margin="5" Padding="5" BorderBrush="Black" BorderThickness="1,1,1,1" CornerRadius="5">
        <StackPanel>
            <s:SciChartLegend x:Name="SciChartLegendControl"
                              s:ThemeManager.Theme="Chrome"
                              Margin="5,5"
                              ScrollViewer.HorizontalScrollBarVisibility="Auto"
                              ScrollViewer.VerticalScrollBarVisibility="Auto"
                              LegendData="{Binding LegendData}"
                              ShowVisibilityCheckboxes="True" />
        </StackPanel>
    </Border>

But it doesn’t shown

Images
  • You must to post comments
0
0

Hello again.
Maybe the problem because I used IRenderableSeriesViewModel instead of IRenderableSeries? But I think it is can be worked too.

private ObservableCollection<IRenderableSeriesViewModel> _renderableSeries;
public ObservableCollection<IRenderableSeriesViewModel> RenderableSeries
{
    get { return _renderableSeries; }
    set
    {
        SetProperty(ref _renderableSeries, value, nameof(RenderableSeries));
    }
}

private ObservableCollection<IAnnotationViewModel> _annotations;
public ObservableCollection<IAnnotationViewModel> Annotations
{
    get { return _annotations; }
    set
    {
        SetProperty(ref _annotations, value, nameof(Annotations));
    }
}

private ChartDataObject _legendData;
public ChartDataObject LegendData
{
    get { return _legendData; }
    set
    {
        SetProperty(ref _legendData, value, nameof(LegendData));
    }
}

private void InitCharts()
{ 
    _legendData = new ChartDataObject();
    _renderableSeries = new ObservableCollection<IRenderableSeriesViewModel>();
    _annotations = new ObservableCollection<IAnnotationViewModel>();

    _lineDataDiameter1 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_DIAMETER_1, LineColor = Colors.OrangeRed, ChartStyle = CHART_LINE_STYLE });
    _lineDataDiameter2 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_DIAMETER_2, LineColor = Colors.BlueViolet, ChartStyle = CHART_LINE_STYLE });
    _lineDataCovering1 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_COVERING_1, LineColor = Colors.LimeGreen, ChartStyle = CHART_LINE_STYLE });
    _lineDataCovering2 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_COVERING_2, LineColor = Colors.DeepSkyBlue, ChartStyle = CHART_LINE_STYLE });
    _lineDataCovering3 = InitChart(new InitChartRequest() { ChartName = CHART_NAME_COVERING_3, LineColor = Colors.White, ChartStyle = CHART_LINE_STYLE });
}

private XyDataSeries<double, double> InitChart(InitChartRequest request)
{
    XyDataSeries<double, double> lineData = new()
    {
        SeriesName = request.ChartName,
    };

    RenderableSeries.Add(new LineRenderableSeriesViewModel()
    {
        Stroke = request.LineColor,
        DataSeries = lineData,
        StyleKey = request.ChartStyle,
    });

    return lineData;
}

As I understand I need write something like _legendData.SeriesInfo = ???(RenderableSeries). But what? I don’t understand. Please help me.

  • You must to post comments
0
0

If the only problem is you cannot find the correct binding to the LegendModifier then this is probably easily solvable

However without a full code sample & solution to reproduce we would be guessing

You’re a supported customer of scichart, why don’t you put together a very simple solution that recreates your application architecture and the problem, and send it over to support.scichart.com? I recommend referring to this forum post in the ticket.

Our team will then be able to help further

  • You must to post comments
0
0

Thank you.
I created the ticket as you recommend

  • You must to post comments
Showing 5 results