c# – 滚动X轴绘图区域 – Silverlight柱系列

我有一个柱系列图表,工作正常.

我有一个功能,我需要添加,我希望horizo​​ntall滚动启用到x轴的绘图区域.

这是屏幕截图:

如果你看到屏幕截图我有六个项目,并且由于更多的项目,条形图非常薄,所以假设我有20个项目,那么条形图将根本不可见.

那么我们可以使X轴条水平滚动吗?

编辑

ResourceDictionary.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:convertor="clr-namespace:ChartingDV.Provider"
    xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:chartingprimitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit">

    <ControlTemplate x:Key="PhoneChartPortraitTemplate" targettype="charting:Chart">
        <Grid>
            <Grid.RowDeFinitions>
                <RowDeFinition Height="Auto"/>
                <RowDeFinition Height="*"/>
                <RowDeFinition Height="Auto"/>
            </Grid.RowDeFinitions>
            <datavis:Title
                Content="{TemplateBinding Title}"
                Style="{TemplateBinding TitleStyle}"/>
            <datavis:Legend x:Name="Legend"
                Grid.Row="2"
                Header="{TemplateBinding LegendTitle}"
                Style="{TemplateBinding LegendStyle}">
                <datavis:Legend.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </datavis:Legend.ItemsPanel>
                <datavis:Legend.Template>
                    <ControlTemplate targettype="datavis:Legend">
                        <Grid>
                            <Grid.RowDeFinitions>
                                <RowDeFinition Height="Auto" />
                                <RowDeFinition />
                            </Grid.RowDeFinitions>
                            <ScrollViewer
                                    Grid.Row="1"
                                    HorizontalScrollBarVisibility="Auto"
                                    VerticalScrollBarVisibility="disabled"
                                    BorderThickness="0"
                                    Padding="0"
                                    IsTabStop="False">
                                <ItemsPresenter
                                        x:Name="Items"
                                        Margin="10,10,10"/>
                            </ScrollViewer>
                        </Grid>
                    </ControlTemplate>
                </datavis:Legend.Template>
            </datavis:Legend>
            <chartingprimitives:EdgePanel
                Grid.Column="0"
                Grid.Row="1"
                x:Name="ChartArea"
                Style="{TemplateBinding ChartAreaStyle}">
                <Grid
                    Canvas.ZIndex="-1"
                    Style="{TemplateBinding PlotAreaStyle}" />
            </chartingprimitives:EdgePanel>
        </Grid>
    </ControlTemplate>

    <!-- Chart Style for Phone -->
    <Style x:Key="PhoneChartStyle" targettype="charting:Chart">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Padding" Value="10" />
        <Setter Property="Palette">
            <Setter.Value>
                <datavis:ResourceDictionaryCollection>
                    <!-- Blue -->
                    <ResourceDictionary>
                        <SolidColorBrush x:Key="Background" Color="#E85F3D"/>
                        <Style x:Key="DataPointStyle" targettype="Control">
                            <Setter Property="Background" Value="{StaticResource Background}" />
                        </Style>
                        <Style x:Key="DataShapestyle" targettype="Shape">
                            <Setter Property="stroke" Value="{StaticResource Background}" />
                            <Setter Property="strokeThickness" Value="2" />
                            <Setter Property="strokeMiterLimit" Value="1" />
                            <Setter Property="Fill" Value="{StaticResource Background}" />
                        </Style>
                    </ResourceDictionary>
                    <!-- Red -->
                    <ResourceDictionary>
                        <SolidColorBrush x:Key="Background" Color="#76D164"/>
                        <Style x:Key="DataPointStyle" targettype="Control">
                            <Setter Property="Background" Value="{StaticResource Background}" />
                        </Style>
                        <Style x:Key="DataShapestyle" targettype="Shape">
                            <Setter Property="stroke" Value="{StaticResource Background}" />
                            <Setter Property="strokeThickness" Value="2" />
                            <Setter Property="strokeMiterLimit" Value="1" />
                            <Setter Property="Fill" Value="{StaticResource Background}" />
                        </Style>
                    </ResourceDictionary>
                    <!-- Light Green -->
                    <ResourceDictionary>
                        <SolidColorBrush x:Key="Background" Color="#648ED1"/>
                        <Style x:Key="DataPointStyle" targettype="Control">
                            <Setter Property="Background" Value="{StaticResource Background}" />
                        </Style>
                        <Style x:Key="DataShapestyle" targettype="Shape">
                            <Setter Property="stroke" Value="{StaticResource Background}" />
                            <Setter Property="strokeThickness" Value="2" />
                            <Setter Property="strokeMiterLimit" Value="1" />
                            <Setter Property="Fill" Value="{StaticResource Background}" />
                        </Style>
                    </ResourceDictionary>
                </datavis:ResourceDictionaryCollection>
            </Setter.Value>
        </Setter>
        <Setter Property="LegendStyle">
            <Setter.Value>
                <Style targettype="datavis:Legend">
                    <Setter Property="HorizontalAlignment" Value="Center"/>
                    <Setter Property="VerticalAlignment" Value="Center"/>
                    <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
                    <Setter Property="Margin" Value="20"/>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="ChartAreaStyle">
            <Setter.Value>
                <Style targettype="Panel">
                    <Setter Property="MinWidth" Value="100" />
                    <Setter Property="MinHeight" Value="75" />
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="PlotAreaStyle">
            <Setter.Value>
                <Style targettype="Grid">
                    <Setter Property="Background" Value="Transparent"/>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="Template" Value="{StaticResource PhoneChartPortraitTemplate}"/>
    </Style>

</ResourceDictionary>

在XAMl文件中:

<charting:Chart Name="barChart"
    Style="{StaticResource PhoneChartStyle}"
    Template="{StaticResource PhoneChartPortraitTemplate}">
    <charting:Chart.Series>
        <charting:ColumnSeries 
            Title="Incorrect"
            IndependentValueBinding="{Binding Key}"
            DependentValueBinding="{Binding Value}"
            AnimationSequence="Simultaneous">
        </charting:ColumnSeries>
        <charting:ColumnSeries                 
            Title="Correct"
            IndependentValueBinding="{Binding Key}"
            DependentValueBinding="{Binding Value}"
            AnimationSequence="Simultaneous">
        </charting:ColumnSeries>
        <charting:ColumnSeries                 
            Title="Skipped"
            IndependentValueBinding="{Binding Key}"
            DependentValueBinding="{Binding Value}"
            AnimationSequence="Simultaneous">
        </charting:ColumnSeries>
    </charting:Chart.Series>
</charting:Chart>

解决方法

最后我已经解决了,但我没有对API进行任何更改,而是我遵循了以下方法.

1)我们可以选择滚动整个图表.

2)使整个条形图滚动,然后删除Y轴值.

3)现在使用网格行定义创建一个具有Y轴值的虚拟布局.这将是您的根网格.

4)现在在根网格内放置图表网格.

5)现在,当您进行n次测试时,您可以滚动图表,但是具有Y轴值的虚拟布局保持不变,因此对于用户来说,它看起来像是滚动条.

请享用 :)

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...