简体   繁体   中英

Is there a way to plot OXYplot graph in custom area in WPF window?

I want to put several graphs in one WPF window using OXYplot library, so there will be some WPF components (like buttons) and some rectangles with graphs. It there a way to do it? In all examples the OXYplot graph occupies the whole WPF window.

I tried to put it inside a rectangle like this, but got an error "The type 'Rectangle' does not support direct content"

<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="932,547,0,0" Stroke="Black" VerticalAlignment="Top" Width="100">
   <oxy:PlotView Model="{Binding Model}"/>
</Rectangle>

Put it in a Panel or decorate it with aa Border :

<Border Background="Yellow" BorderBrush="Black" BorderThickness="1" Padding="10">
    <oxy:PlotView Model="{Binding Model}"/>
</Border>

A PlotView is just a custom Control that you can use in your layout as you would use any other control in WPF.

To keep it simple, you could use Grid as well, to arrange multiple PlotView and buttons in desired layout.

<Grid Margin="10">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid Grid.Column="0" Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <oxy:PlotView Height="500" Width="500" Model="{Binding GraphModel1}"/>
            <Button Grid.Column="1" Content="Click"/>
        </Grid>
        <Grid Grid.Column="1" Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <oxy:PlotView Height="500" Width="500" Model="{Binding GraphModel2}"/>
            <Button Grid.Column="1" Content="Click"/>
        </Grid>
        <Grid Grid.Column="1" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <oxy:PlotView Height="500" Width="500" Model="{Binding GraphModel3}"/>
            <Button Grid.Column="1" Content="Click"/>
        </Grid>
        <Grid Grid.Column="0" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <oxy:PlotView Height="500" Width="500" Model="{Binding GraphModel4}"/>
            <Button Grid.Column="1" Content="Click"/>
        </Grid>
    </Grid>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM