1:柱图
<UserControl x:Class="IShiTong.Project.WpfChart.Common.Bar3DControlExtend"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxdb="http://schemas.devexpress.com/winfx/2008/xaml/demobase"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:local="clr-namespace:IShiTong.Project.WpfChart.Common"
mc:Ignorable="d"
d:DesignHeight="419" x:Name="thiself" d:DesignWidth="475" Foreground="#67FFFFFF" Background="#67FFFFFF" BorderBrush="#67FFFFFF">
<dxc:ChartControl Name="chart" MouseMove="chart_MouseMove" QueryChartCursor="chart_QueryChartCursor"
MouseLeave="chart_MouseLeave" EnableAnimation="True" BorderThickness="0" Height="Auto" Width="Auto" FontWeight="Bold" FontSize="14">
<dxc:ChartControl.Diagram >
<dxc:XYDiagram2D Background="Transparent" BarDistance="0.04" Rotated="False">
<dxc:XYDiagram2D.AxisY>
<dxc:AxisY2D>
<dxc:AxisY2D.Label>
<dxc:AxisLabel />
</dxc:AxisY2D.Label>
</dxc:AxisY2D>
</dxc:XYDiagram2D.AxisY>
<dxc:XYDiagram2D.AxisX>
<dxc:AxisX2D>
<dxc:AxisX2D.Label>
<dxc:AxisLabel Staggered="False" Visible="True" Foreground="#FF363636" Padding="5,10,5,1" FontSize="15" />
</dxc:AxisX2D.Label>
</dxc:AxisX2D>
</dxc:XYDiagram2D.AxisX>
<dxc:XYDiagram2D.DefaultPane>
<dxc:Pane EnableAxisYNavigation="False" EnableAxisXNavigation="False" Background="Transparent" DomainBrush="Transparent">
</dxc:Pane>
</dxc:XYDiagram2D.DefaultPane>
<dxc:XYDiagram2D.Series>
</dxc:XYDiagram2D.Series>
</dxc:XYDiagram2D>
</dxc:ChartControl.Diagram>
<dxc:ChartControl.Legend >
<dxc:Legend ReverseItems="True" Background="Transparent" Foreground="#FF363636"></dxc:Legend>
</dxc:ChartControl.Legend>
<dxc:ChartControl.Titles>
<dxc:Title Background="Transparent" Dock="Top" HorizontalAlignment="Left" Content="{Binding Path=TitleText,ElementName=thiself,Mode=TwoWay}" Foreground="#08318B"></dxc:Title>
<dxc:Title Background="Transparent" Dock="Top" HorizontalAlignment="Center" Content="{Binding Path=TitleDate,ElementName=thiself,Mode=TwoWay}" Foreground="#FFA306"></dxc:Title>
</dxc:ChartControl.Titles>
<dxc:ChartControl.Background>
<ImageBrush ImageSource="/IShiTong.Project.WpfChart.Common;component/Images/back.jpg" />
</dxc:ChartControl.Background>
</dxc:ChartControl>
</UserControl>
cs文件、
public Bar3DControlExtend()
{
InitializeComponent();
//this.SetStyle(ControlStyles.AllPaintingInWmPaint | //不擦除背景 ,减少闪烁
// ControlStyles.OptimizedDoubleBuffer | //双缓冲
// ControlStyles.UserPaint | //使用自定义的重绘事件,减少闪烁
// ControlStyles.ResizeRedraw |
// ControlStyles.Selectable |
// ControlStyles.SupportsTransparentBackColor,
// true);
this.TitleDate = DateTime.Now.ToString("yyyy年MM月dd日");
this.Loaded += new RoutedEventHandler(Bar3DControlExtend_Loaded);
this.chart.Palette = new IShiTongPalette();
}
public ChartControl CurrentChart
{
get { return this.chart; }
set { this.chart = value; }
}
void Bar3DControlExtend_Loaded(object sender, RoutedEventArgs e)
{
this.chart.Animate();
}
public BarSideBySideSeries2D GetBaseBarSerie(string name,string displayname)
{
BarSideBySideSeries2D BarSeries = new BarSideBySideSeries2D();
//BarSeries.Name = name;
BarSeries.DisplayName = displayname;
BarSeries.AnimationAutoStartMode = AnimationAutoStartMode.SetStartState;
BarSeries.Model=new GlassCylinderBar2DModel();
SeriesLabel label = new SeriesLabel(){Indent=20,ResolveOverlappingMode= ResolveOverlappingMode.Default,ConnectorThickness=1, Visible=true};
BarSeries.Label = label;
return BarSeries;
}
public void InitData(List<List<object>> datasource, string displayname, string x, string y)
{
foreach (var item in datasource)
{
if (item.Count > 0)
{
string disname = Utils.GetValueByName(item[0], displayname);
BarSideBySideSeries2D line = this.GetBaseBarSerie(disname, disname);
foreach (var child in item)
{
string xvalue = Utils.GetValueByName(child, x);
if (!string.IsNullOrWhiteSpace(xvalue))
{
if (xvalue.Length > 5)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(xvalue.Substring(0, 5));
sb.AppendLine(xvalue.Substring(5, xvalue.Length - 5));
xvalue = sb.ToString();
}
}
string yvalue = Utils.GetValueByName(child, y);
line.Points.Add(new SeriesPoint(xvalue, double.Parse(yvalue)));
}
this.chart.Diagram.Series.Add(line);
}
}
}
public string TitleText
{
get { return (string)GetValue(TitleTextProperty); }
set { SetValue(TitleTextProperty, value); }
}
public static readonly DependencyProperty TitleTextProperty =
DependencyProperty.Register("TitleText", typeof(string), typeof(Bar3DControlExtend));
//readonly
public string TitleDate
{
get { return (string)GetValue(TitleDateProperty); }
set { SetValue(TitleDateProperty, value); }
}
public static readonly DependencyProperty TitleDateProperty =
DependencyProperty.Register("TitleDate", typeof(string), typeof(Bar3DControlExtend));
2 饼图
<local:ChartsDemoModule x:Class="IShiTong.Project.WpfChart.Common.Pie3DControl" Height="400" Width="800"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxdb="http://schemas.devexpress.com/winfx/2008/xaml/demobase"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:local="clr-namespace:IShiTong.Project.WpfChart.Common"
x:Name="thiself" Foreground="#67FFFFFF" Background="#67FFFFFF" BorderBrush="#67FFFFFF" OverridesDefaultStyle="False" Opacity="1">
<local:ChartsDemoModule.Resources>
<ResourceDictionary>
<ObjectDataProvider x:Key="Pie3DModelKindDataProvider" ObjectType="{x:Type dxc:Pie3DModel}" MethodName="GetPredefinedKinds" />
<DoubleAnimation x:Key="ExplodeAnimation" To="0.2" Duration="0:0:0.5" />
<DoubleAnimation x:Key="CollapseAnimation" To="0.0" Duration="0:0:0.5" />
<Storyboard x:Key="InitialAnimation">
<DoubleAnimation Storyboard.TargetName="diagramAnimation" Storyboard.TargetProperty="Progress" From="0.1" To="1.0" Duration="0:0:2" />
</Storyboard>
</ResourceDictionary>
</local:ChartsDemoModule.Resources>
<local:ChartsDemoModule.Triggers>
<EventTrigger RoutedEvent="local:ChartsDemoModule.ModuleAppear">
<EventTrigger.Actions>
<BeginStoryboard Storyboard="{StaticResource InitialAnimation}" HandoffBehavior="Compose" />
</EventTrigger.Actions>
</EventTrigger>
</local:ChartsDemoModule.Triggers>
<dxdb:DemoModuleControl>
<Grid Height="Auto" Width="Auto">
<dxc:ChartControl Name="chart" MouseUp="chart_MouseUp" MouseDown="chart_MouseDown"
QueryChartCursor="chart_QueryChartCursor" BorderThickness="0" IsManipulationEnabled="True" SizeChanged="chart_SizeChanged" EnableAnimation="True" FontWeight="Bold" FontSize="14">
<dxc:ChartControl.AnimationRecords>
<dxc:ChartAnimationRecord x:Name="diagramAnimation" Progress="0">
<dxc:ChartAnimationRecord.Animations>
<dxc:Diagram3DAnimation InitialZoomPercent="1">
<dxc:Diagram3DAnimation.InitialRotation>
<dxc:AnimationRotation Order="YXZ" AngleX="0" AngleY="-50" />
</dxc:Diagram3DAnimation.InitialRotation>
<dxc:Diagram3DAnimation.Actions>
<dxc:Diagram3DZoomAction FinalZoomPercent="100" />
<dxc:Diagram3DRotationAction>
<dxc:Diagram3DRotationAction.Rotation>
<dxc:AnimationRotation AngleX="-40" AngleY="210" />
</dxc:Diagram3DRotationAction.Rotation>
</dxc:Diagram3DRotationAction>
</dxc:Diagram3DAnimation.Actions>
</dxc:Diagram3DAnimation>
</dxc:ChartAnimationRecord.Animations>
</dxc:ChartAnimationRecord>
</dxc:ChartControl.AnimationRecords>
<dxc:ChartControl.Diagram>
<dxc:SimpleDiagram3D ZoomPercent="1">
<dxc:SimpleDiagram3D.ContentTransform>
<MatrixTransform3D>
<MatrixTransform3D.Matrix>
<Matrix3D M11="0.84618084560776707" M12="0" M13="0.53289584022257508" M14="0" M21="0.46650954764013092" M22="-0.48335667549660682" M23="-0.7407666071128397" M24="0" M31="0.25757876171595484" M32="0.87542351136628027" M33="-0.40900716040187785" M34="0" M44="1" OffsetX="0" OffsetY="0" OffsetZ="0" />
</MatrixTransform3D.Matrix>
</MatrixTransform3D>
</dxc:SimpleDiagram3D.ContentTransform>
<dxc:SimpleDiagram3D.Series>
<dxc:PieSeries3D Name="Series" ArgumentScaleType="Qualitative" DepthTransform="0.5" HoleRadiusPercent="0" AnimationAutoStartMode="PlayOnce">
<dxc:PieSeries3D.PointOptions>
<dxc:PointOptions PointView="ArgumentAndValues">
<dxc:PieSeries.PercentOptions>
<dxc:PercentOptions ValueAsPercent="False" />
</dxc:PieSeries.PercentOptions>
<dxc:PointOptions.ValueNumericOptions>
<dxc:NumericOptions />
</dxc:PointOptions.ValueNumericOptions>
</dxc:PointOptions>
</dxc:PieSeries3D.PointOptions>
<dxc:PieSeries3D.Model>
<dxc:SemiRectanglePie3DModel />
</dxc:PieSeries3D.Model>
<dxc:PieSeries3D.Label>
<dxc:SeriesLabel Visible="False" Indent="20" RenderMode="CustomShape" />
</dxc:PieSeries3D.Label>
<dxc:PieSeries3D.Points>
<!--<dxc:SeriesPoint Argument="USA" Value="9.63142" />
<dxc:SeriesPoint Argument="Canada" Value="9.98467" />
<dxc:SeriesPoint Argument="Russia" Value="17.0752" />
<dxc:SeriesPoint Argument="Others" Value="81.2" />
<dxc:SeriesPoint Argument="India" Value="3.28759" />
<dxc:SeriesPoint Argument="Australia" Value="7.68685" />
<dxc:SeriesPoint Argument="Brazil" Value="8.511965" />
<dxc:SeriesPoint Argument="China" Value="9.59696" />-->
</dxc:PieSeries3D.Points>
<dxc:PieSeries3D.LegendPointOptions>
<dxc:PointOptions PointView="ArgumentAndValues">
<dxc:PieSeries.PercentOptions>
<dxc:PercentOptions ValueAsPercent="False"></dxc:PercentOptions>
</dxc:PieSeries.PercentOptions>
</dxc:PointOptions>
</dxc:PieSeries3D.LegendPointOptions>
</dxc:PieSeries3D>
</dxc:SimpleDiagram3D.Series>
</dxc:SimpleDiagram3D>
</dxc:ChartControl.Diagram>
<dxc:ChartControl.Titles>
<dxc:Title Background="Transparent" Dock="Top" HorizontalAlignment="Left" Content="{Binding Path=TitleText,ElementName=thiself,Mode=TwoWay}" Foreground="#08318B"></dxc:Title>
<dxc:Title Background="Transparent" Dock="Top" HorizontalAlignment="Center" Content="{Binding Path=TitleDate,ElementName=thiself,Mode=TwoWay}" Foreground="#FFA306"></dxc:Title>
</dxc:ChartControl.Titles>
<dxc:ChartControl.Legend>
<dxc:Legend Background="Transparent" Foreground="#FF363636"></dxc:Legend>
</dxc:ChartControl.Legend>
<dxc:ChartControl.Background>
<ImageBrush ImageSource="/IShiTong.Project.WpfChart.Common;component/Images/back.jpg" />
</dxc:ChartControl.Background>
</dxc:ChartControl>
</Grid>
</dxdb:DemoModuleControl>
</local:ChartsDemoModule>
cs文件
const int clickDelta = 200;
bool isLeftMouseButtonReleased = true;
int mouseDownTime;
public override ChartControl ActualChart { get { return chart; } }
public Pie3D()
{
InitializeComponent();
this.TitleDate = DateTime.Now.ToString("yyyy年MM月dd日");
this.Loaded += new RoutedEventHandler(Pie3DControl_Loaded);
this.ModuleAppear += new RoutedEventHandler(Pie3DControl_ModuleAppear);
}
public ChartControl CurrentChart
{
get { return this.chart; }
set { this.chart = value; }
}
public string TitleText
{
get { return (string)GetValue(TitleTextProperty); }
set { SetValue(TitleTextProperty, value); }
}
public static readonly DependencyProperty TitleTextProperty =
DependencyProperty.Register("TitleText", typeof(string), typeof(Pie3D));
//readonly
public string TitleDate
{
get { return (string)GetValue(TitleDateProperty); }
set { SetValue(TitleDateProperty, value); }
}
public static readonly DependencyProperty TitleDateProperty =
DependencyProperty.Register("TitleDate", typeof(string), typeof(Pie3D));
void Pie3DControl_ModuleAppear(object sender, RoutedEventArgs e)
{
this.chart.Animate();
}
void Pie3DControl_Loaded(object sender, RoutedEventArgs e)
{
this.RaiseModuleAppear();
}
bool IsClick(int mouseUpTime)
{
return mouseUpTime - mouseDownTime < clickDelta;
}
void chart_MouseDown(object sender, MouseButtonEventArgs e)
{
}
void chart_MouseUp(object sender, MouseButtonEventArgs e)
{
}
void chart_QueryChartCursor(object sender, QueryChartCursorEventArgs e)
{
}
private void chart_SizeChanged(object sender, SizeChangedEventArgs e)
{
}
private PieSeries3D GetBaseBarSerie(string name, string displayname)
{
PieSeries3D pie = new PieSeries3D() { ArgumentScaleType = ScaleType.Qualitative, DepthTransform = 0.5, HoleRadiusPercent = 0, AnimationAutoStartMode = AnimationAutoStartMode.PlayOnce };
PointOptions option = new PointOptions() { PointView = PointView.ArgumentAndValues };
pie.PointOptions = option;
PercentOptions po = new PercentOptions();
po.ValueAsPercent = false;
PieSeries3D.SetPercentOptions(option, po);
pie.Model = new SemiRectanglePie3DModel();
pie.Label = new SeriesLabel() { Visible = true, Indent = 20, RenderMode = LabelRenderMode.CustomShape, ResolveOverlappingMode = ResolveOverlappingMode.JustifyAllAroundPoint };
pie.LegendPointOptions = option;
PieSeries3D.SetLabelPosition(pie.Label, PieLabelPosition.Inside);
return pie;
}
public void InitData(List<List<object>> datasource, string displayname, string x, string y)
{//"Name","X","Y"
string disname = Utils.GetValueByName(datasource[0], displayname);
PieSeries3D pie = this.GetBaseBarSerie(displayname, displayname);
foreach (var item in datasource)
{
if (item.Count > 0)
{
foreach (var child in item)
{
string xvalue = Utils.GetValueByName(child, x);
if (!string.IsNullOrWhiteSpace(xvalue))
{
if (xvalue.Length > 5)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(xvalue.Substring(0, 5));
sb.AppendLine(xvalue.Substring(5, xvalue.Length - 5));
xvalue =sb.ToString();
}
}
string yvalue = Utils.GetValueByName(child, y);
if (datasource.Count == 1)
{
pie.Points.Add(new SeriesPoint( xvalue, double.Parse(yvalue)));
}
else
{
pie.Points.Add(new SeriesPoint(xvalue, double.Parse(yvalue)));
}
}
}
}
this.chart.Diagram.Series.Add(pie);
}
3 折线
<UserControl x:Class="IShiTong.Project.WpfChart.Common.Line2DControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxdb="http://schemas.devexpress.com/winfx/2008/xaml/demobase"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:local="clr-namespace:IShiTong.Project.WpfChart.Common"
mc:Ignorable="d"
d:DesignHeight="419" x:Name="thiself" d:DesignWidth="475" Foreground="#67FFFFFF" Background="#67FFFFFF" BorderBrush="#67FFFFFF"
>
<UserControl.Resources>
<DataTemplate x:Key="AxisXLabelTemplate">
<Border Padding="{Binding Path=Label.Padding}"
Background="{Binding Path=Label.Background}"
BorderBrush="{Binding Path=Label.BorderBrush}"
BorderThickness="{Binding Path=Label.BorderThickness}">
<Border.LayoutTransform>
<RotateTransform Angle="90" />
</Border.LayoutTransform>
<ContentPresenter Content="{Binding Path=Content}"/>
</Border>
</DataTemplate>
</UserControl.Resources>
<dxc:ChartControl Name="chart" EnableAnimation="True" Height="Auto" Width="Auto" FontSize="14" FontWeight="Bold">
<dxc:ChartControl.Background>
<ImageBrush ImageSource="/IShiTong.Project.WpfChart.Common;component/Images/back.jpg" />
</dxc:ChartControl.Background>
<dxc:ChartControl.Titles>
<dxc:Title Background="Transparent" Dock="Top" HorizontalAlignment="Left" Content="{Binding Path=TitleText,ElementName=thiself,Mode=TwoWay}" Foreground="#08318B"></dxc:Title>
<dxc:Title Background="Transparent" Dock="Top" HorizontalAlignment="Center" Content="{Binding Path=TitleDate,ElementName=thiself,Mode=TwoWay}" Foreground="#FFA306"></dxc:Title>
</dxc:ChartControl.Titles>
<dxc:ChartControl.Diagram >
<dxc:XYDiagram2D x:Name="diagram">
<dxc:XYDiagram2D.AxisX>
<dxc:AxisX2D>
<dxc:AxisX2D.Label>
<dxc:AxisLabel Foreground="#FF363636" FontSize="15" />
</dxc:AxisX2D.Label>
</dxc:AxisX2D>
</dxc:XYDiagram2D.AxisX>
<dxc:XYDiagram2D.DefaultPane>
<dxc:Pane EnableAxisYNavigation="False" EnableAxisXNavigation="False" Background="Transparent" DomainBrush="Transparent">
</dxc:Pane>
</dxc:XYDiagram2D.DefaultPane>
<dxc:XYDiagram2D.AxisY>
<dxc:AxisY2D MinorCount="1" GridLinesMinorVisible="False">
<dxc:AxisY2D.Label>
<dxc:AxisLabel />
</dxc:AxisY2D.Label>
<dxc:AxisY2D.Range>
<dxc:AxisRange dxc:AxisY2D.AlwaysShowZeroLevel="False" />
</dxc:AxisY2D.Range>
</dxc:AxisY2D>
</dxc:XYDiagram2D.AxisY>
<dxc:XYDiagram2D.Series>
<!--<dxc:LineSeries2D DisplayName="Temperature (F)" AnimationAutoStartMode="SetStartState">
<dxc:LineSeries2D.SeriesAnimation>
<dxc:Line2DStretchFromNearAnimation Duration="0:0:2"/>
</dxc:LineSeries2D.SeriesAnimation>
<dxc:LineSeries2D.PointAnimation>
<dxc:Marker2DSlideFromTopAnimation Duration="0:0:2"/>
</dxc:LineSeries2D.PointAnimation>
<dxc:LineSeries2D.Label>
<dxc:SeriesLabel dxc:MarkerSeries2D.Angle="90"/>
</dxc:LineSeries2D.Label>
<dxc:LineSeries2D.Points>
<dxc:SeriesPoint Value="56.48" Argument="A"/>
<dxc:SeriesPoint Value="53.78" Argument="B"/>
<dxc:SeriesPoint Value="57.74" Argument="C"/>
<dxc:SeriesPoint Value="64.4" Argument="D"/>
<dxc:SeriesPoint Value="72.5" Argument="E"/>
</dxc:LineSeries2D.Points>
</dxc:LineSeries2D>-->
</dxc:XYDiagram2D.Series>
</dxc:XYDiagram2D>
</dxc:ChartControl.Diagram>
<dxc:ChartControl.Legend>
<dxc:Legend VerticalPosition="Top" HorizontalPosition="RightOutside" Orientation="Vertical" IndentFromDiagram="0" Padding="0" Margin="0" BorderBrush="{Binding ElementName=chart, Path=BorderBrush}" Foreground="#FF363636">
<dxc:Legend.Background>
<SolidColorBrush />
</dxc:Legend.Background>
</dxc:Legend>
</dxc:ChartControl.Legend>
</dxc:ChartControl>
</UserControl>
cs文件
public Line2DControl()
{
InitializeComponent();
this.TitleDate = DateTime.Now.ToString("yyyy年MM月dd日");
this.Loaded += new RoutedEventHandler(Line2DControl_Loaded);
this.chart.Palette = new IShiTongPalette();
}
void Line2DControl_Loaded(object sender, RoutedEventArgs e)
{
this.chart.Animate();
}
public ChartControl CurrentChart
{
get { return this.chart; }
set {
this.chart = value;
}
}
public LineSeries2D CreateBaseSerie()
{
LineSeries2D LineSeries = new LineSeries2D();
//创建line动画
Line2DStretchFromNearAnimation lineanimation = new Line2DStretchFromNearAnimation();
lineanimation.Duration = new TimeSpan(0, 0, 2);
LineSeries.SeriesAnimation = lineanimation;
//创建point动画
Marker2DSlideFromTopAnimation pointanimation = new Marker2DSlideFromTopAnimation();
pointanimation.Duration = new TimeSpan(0, 0, 2);
LineSeries.PointAnimation = pointanimation;
SeriesLabel lable = new SeriesLabel();
MarkerSeries2D.SetAngle(lable, 90);
LineSeries.Label = lable;
return LineSeries;
}
public string TitleText
{
get { return (string)GetValue(TitleTextProperty); }
set { SetValue(TitleTextProperty, value); }
}
public static readonly DependencyProperty TitleTextProperty =
DependencyProperty.Register("TitleText", typeof(string), typeof(Line2DControl));
//readonly
public string TitleDate
{
get { return (string)GetValue(TitleDateProperty); }
set { SetValue(TitleDateProperty, value); }
}
public static readonly DependencyProperty TitleDateProperty =
DependencyProperty.Register("TitleDate", typeof(string), typeof(Line2DControl));
public void InitData(List<List<object>> datasource,string displayname,string x,string y)
{
//if (!string.IsNullOrWhiteSpace(x))
//{
// if (x.Length > 5)
// {
// StringBuilder sb = new StringBuilder();
// sb.AppendLine(x.Substring(0, 5));
// sb.AppendLine(x.Substring(5, x.Length - 5));
// x = sb.ToString();
// }
//}
foreach (var item in datasource)
{
if (item.Count > 0)
{
LineSeries2D line = this.CreateBaseSerie();
line.DisplayName = Utils.GetValueByName(item[0], displayname);
foreach (var child in item)
{
line.Points.Add(new SeriesPoint(Utils.GetValueByName(child, x), double.Parse(Utils.GetValueByName(child, y))));
}
this.chart.Diagram.Series.Add(line);
}
}
}
public DataTemplate GetResource()
{
return this.Resources["AxisXLabelTemplate"] as DataTemplate;
}
4 调用方式
public string ProduceImageByEntity(int showinfr, List<PushResult> pushResultList, long moduleid, string titleText, int key, System.Windows.Forms.Integration.ElementHost elementHost)
{
string datepath = FileImagePath();
string savepath = cacheDirectory + titleText + "&" + key.ToString() + datepath + ".txt";
lock (obj)
{
elementHost.Size = this.Size;
elementHost.Name = "elementHost";
if (showinfr == Helpers.SystemConst.INDEXONE)
{
WpfChart.Common.Bar3DControlExtend bar3d = new WpfChart.Common.Bar3DControlExtend();
bar3d.CurrentChart.EnableAnimation = false;
bar3d.TitleText = titleText;
bar3d.InitData(ChangeLx(pushResultList, showinfr), "Pushitemname", "Xvalue", "Yvalue");
elementHost.Child = bar3d;
}
else if (showinfr == Helpers.SystemConst.INDEXTWO)
{
WpfChart.Common.Pie3D Pie3D = new WpfChart.Common.Pie3D();
Pie3D.CurrentChart.EnableAnimation = false;
Pie3D.TitleText = titleText;
Pie3D.InitData(ChangeLx(pushResultList, showinfr), "Pushitemname", "Xvalue", "Yvalue");
elementHost.Child = Pie3D;
}
else if (showinfr == Helpers.SystemConst.INDEXTHREE)
{
WpfChart.Common.Line2DControl Line2D = new WpfChart.Common.Line2DControl();
Line2D.TitleText = titleText;
Line2D.CurrentChart.EnableAnimation = false;
Line2D.InitData(ChangeLx(pushResultList, showinfr), "Pushitemname", "Xvalue", "Yvalue");
elementHost.Child = Line2D;
}
else if (showinfr == Helpers.SystemConst.INDEXFOUR)
{
WpfChart.Common.StackedBar3DControl Stacker3d = new WpfChart.Common.StackedBar3DControl(); ;
Stacker3d.CurrentChart.EnableAnimation = false;
Stacker3d.TitleStackedBar3dText = titleText;
Stacker3d.InitData(ChangeLx(pushResultList, showinfr), "Pushitemname", "Xvalue", "Yvalue");
elementHost.Child = (System.Windows.UIElement)Stacker3d;
}
}
using (Bitmap tobit = new Bitmap(this.Width, this.Height))
{
this.Controls.Add(elementHost);
this.DrawToBitmap(tobit, new Rectangle(0, 0, this.Width, this.Height));
if (!string.IsNullOrWhiteSpace(savepath))
{
byte[] bitbyte =Helpers.CPlusHelper.SerializeObject(tobit);
if (bitbyte != null)
{
File.WriteAllBytes(savepath, bitbyte);
}
}
//tobit.Save(savepath);
}
foreach (System.Windows.Forms.Integration.ElementHost control in this.Controls)
{
if (!control.IsDisposed)
{
control.Dispose();
}
}
this.Controls.Remove(elementHost);
System.GC.Collect();
return savepath;
}
private List<List<object>> ChangeLx(List<PushResult> list, int showfrm)
{
List<List<object>> changelist = new List<List<object>>();
if (list == null || list.Count <= Helpers.SystemConst.INDEXZERO)
{
return changelist;
}
if (showfrm.Equals(Helpers.SystemConst.INDEXTHREE))
{
IEnumerable<IGrouping<string, PushResult>> eventLst = list.OrderBy(evnt => evnt.Pushitemname).ToList().GroupBy(evnt => evnt.Pushitemname).ToList();
foreach (IGrouping<string, PushResult> eventGroup in eventLst)
{
List<PushResult> lt = eventGroup.ToList();
List<object> listobj = new List<object>();
foreach (PushResult entity in lt)
{
object obj = new ValueTable(entity.Pushitemname, entity.Xvalue, double.Parse(entity.YValue));
listobj.Add(obj);
}
changelist.Add(listobj);
}
}
else
{
foreach (var item in list)
{
List<object> listobj = new List<object>();
object obj = new ValueTable(item.Pushitemname, item.Xvalue, double.Parse(item.YValue));
listobj.Add(obj);
changelist.Add(listobj);
}
}
return changelist;
}
private void PushGdiBar_Load(object sender, EventArgs e)
{
}
}
#region 统计项数据形式集
class ValueTable
{
private string pushResult;
public string PushResult
{
get { return pushResult; }
set { this.pushResult = value; }
}
private string xvalue;
public string Xvalue
{
get { return xvalue; }
set { this.xvalue = value; }
}
private double yvale;
public double Yvalue
{
get { return yvale; }
set { this.yvale = value; }
}
public ValueTable(string pushResult, string xvalue, double yvale)
{
this.pushResult = pushResult;
this.xvalue = xvalue;
this.yvale = yvale;
}
}
#endregion
实体
//返回结果
[Serializable]
[DataContract]
public class PushResult
{
public PushResult()
{ }
public PushResult(string pushitemname, string xvalue, string yvalue)
{
this.pushitemname = pushitemname;
this.xvalue = xvalue;
this.yvalue = yvalue;
}
/// <summary>
///推送项名称
/// </summary>
private string pushitemname;
public string Pushitemname
{
get { return pushitemname; }
set { this.pushitemname = value; }
}
/// <summary>
/// X轴值
/// </summary>
private string xvalue;
public string Xvalue
{
get { return xvalue; }
set { this.xvalue = value; }
}
/// <summary>
/// Y轴点值
/// </summary>
private string yvalue;
public string YValue
{
get { return yvalue; }
set { this.yvalue = value; }
}
}