如何在Windows Phone中显示代码背后的图表

时间:2014-05-09 16:18:54

标签: c# xaml windows-phone

我在Windows手机应用中创建了一个图表。这是我的代码XAML

<amq:SerialChart x:Name="line"  DataSource="{Binding results}" CategoryValueMemberPath="month"
 AxisForeground="White"
 PlotAreaBackground="Black"
 GridStroke="DarkGray"  >
                <amq:SerialChart.Graphs>
                    <amq:LineGraph Title="Sales" ValueMemberPath="actual" Brush="red" StrokeThickness="5" />
                </amq:SerialChart.Graphs>

            </amq:SerialChart>

如何使用c#(仅限代码)

编写此XAML

2 个答案:

答案 0 :(得分:1)

  

如何使用c#(仅限代码)

编写此XAML

一般来说,这通常不是一个好主意。但如果你必须,你会使用这些方面的东西:

var chart = new SerialChart
{
    CategoryValueMemberPath = "month",
    AxisForeground = new SolidColorBrush(Colors.White),
    PlotAreaBackground = new SolidColorBrush(Colors.Black),
    GridStroke = new SolidColorBrush(Colors.DarkGray)
};
chart.SetBinding(SerialChart.DataSourceProperty, new Binding("results"));

var lineGraph = new LineGraph
{
    Title = "Sales",
    ValueMemberPath = "actual",
    Brush = new SolidColorBrush(Colors.Red),
    StrokeThickness = "5"
};
chart.Graphs.Add(lineGraph);

然后您只需要使用例如stackPanel.Children.Add(chart)将图表添加到页面/容器中。

答案 1 :(得分:0)

var chart = new SerialChart
{
    CategoryValueMemberPath = "month",
    AxisForeground = new SolidColorBrush(Colors.White),
    PlotAreaBackground = new SolidColorBrush(Colors.Black),
    GridStroke = new SolidColorBrush(Colors.DarkGray)
};
chart.SetValue(SerialChart.DataSourceProperty, new Binding("results"));

var lineGraph = new LineGraph
{
    Title = "Sales",
    ValueMemberPath = "actual",
    Brush = new SolidColorBrush(Colors.Red),
    StrokeThickness = 5
};
chart.Graphs.Add(lineGraph);