WPF MVVM Live Charts设置了行系列的起点

时间:2017-07-24 21:18:27

标签: c# wpf livecharts

我正在使用WPF MVVM Live Charts,当我有很大的负值时,它会将起点更改为一个较大的负数。我想知道是否有一个设置,我总是可以从0开始。

这方面的例子如下图所示。它以-1,000,000而不是0开始每一行。

enter image description here

我的C#代码

private string[] _customerLabels;
public string[] CustomerLabels
{
    get { return _customerLabels; }
    set { SetProperty(ref _customerLabels, value); }
}

private SeriesCollection _customerSalesData;
public SeriesCollection CustomerSalesData
{
    get { return _customerSalesData; }
    set { SetProperty(ref _customerSalesData, value); }
}

private void PopulateCustomerGraph()
{
    var seriesCollectionRowSales = new SeriesCollection();
    var rowSeriesSales = new RowSeries();
    var rowValuesSales = new ChartValues<double>();

    var groupedData = BackLogListing
        .GroupBy(m => m.CustomerId)
        .Select(m => new
        {
            Key = m.Key,
            Sales = m.Sum(x => x.Sales)
        })
        .OrderByDescending(m => m.Key);

    CustomerLabels = groupedData.Select(m => m.Key).ToArray();

    rowValuesSales.AddRange(groupedData.Select(m => (double)m.Sales).ToArray());
    rowSeriesSales.Title = "Sales by Customer";
    rowSeriesSales.Values = rowValuesSales;
    seriesCollectionRowSales.Add(rowSeriesSales);

    CustomerSalesData = seriesCollectionRowSales;
}

我的XAML

<lvc:CartesianChart Name="SalesByCustomer"
                    Series="{Binding CustomerSalesData}"
                    DataClickCommand="{Binding ShowCustomerDetailsCommand}"
                    LegendLocation="None"
                    MinHeight="500"
                    Margin="15">
    <lvc:CartesianChart.AxisX>
        <lvc:Axis Title="Dollars"
                    LabelFormatter="{Binding DollarsFormatter}">
            <lvc:Axis.Separator>
                <lvc:Separator IsEnabled="True"></lvc:Separator>
            </lvc:Axis.Separator>
        </lvc:Axis>
    </lvc:CartesianChart.AxisX>
    <lvc:CartesianChart.AxisY>
        <lvc:Axis Title="Customers"
                    Labels="{Binding CustomerLabels}">
            <lvc:Axis.Separator>
                <lvc:Separator IsEnabled="True"
                                Step="1"></lvc:Separator>
            </lvc:Axis.Separator>
        </lvc:Axis>
    </lvc:CartesianChart.AxisY>
    <lvc:CartesianChart.DataTooltip>
        <lvc:DefaultTooltip SelectionMode="SharedYValues"></lvc:DefaultTooltip>
    </lvc:CartesianChart.DataTooltip>
</lvc:CartesianChart>

1 个答案:

答案 0 :(得分:0)

使用Axis.MinValue属性,当此属性为double.NaN时(默认),图表会根据当前数据决定图表的限制。

<lvc:CartesianChart>
    <lvc:CartesianChart.Series>
        <lvc:LineSeries AreaLimit="4" Values="{Binding Values}"/>
    </lvc:CartesianChart.Series>
    <lvc:CartesianChart.AxisX >
        <lvc:Axis MinValue="0" ShowLabels="{Binding ElementName=CheckBox, Path=IsChecked}"></lvc:Axis>
    </lvc:CartesianChart.AxisX>
</lvc:CartesianChart>