I create a chart in my windows phone app.this is my code 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>
How can i write this XAML with c# (code behind only)
How can i write this XAML with c# (code behind only)
In general this is usually not a good idea. But if you must, you would use something along these lines:
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);
Then you would just need to add the chart to the page/container using for example stackPanel.Children.Add(chart)
.
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);
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.