PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Cannot show color of LineSeries in charts of WPF toolkit
http://forum.pdfsharp.com/viewtopic.php?f=3&t=2890
Page 1 of 1

Author:  raoulruan [ Fri Aug 08, 2014 6:18 am ]
Post subject:  Cannot show color of LineSeries in charts of WPF toolkit

I wrote the code as below and I want output the chart1 in pdf file
I found that the lineseries in the chart1 is correctly printed into PDF file, but the color of the polyline missed.
It seems show the same color for all polylines of all lineseries.
I pastes my testing code below and hope you kindly enough to give an answer to me. Thanks a lot.

In xaml file :
<Window x:Class="DrawPicture.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
Title="MainWindow" Height="22cm" Width="30.7cm">
<StackPanel>
<DVC:Chart Name="chart1" Title="Pic1" Height="200" Width="300">
<DVC:Chart.Axes>
<DVC:LinearAxis Orientation="Y" Location="Left" >
</DVC:LinearAxis>
</DVC:Chart.Axes>
</DVC:Chart>
<Button Click="Button_Click_1">HELLO</Button>
</StackPanel>

</Window>
In xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
chart1.DataContext = new MyClass();
LineSeries series1 = new LineSeries();
series1.ItemsSource = (chart1.DataContext as MyClass).source1;
series1.IndependentValueBinding = new Binding("Key");
series1.DependentValueBinding = new Binding("Value");
chart1.Series.Add(series1);
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
PdfXpsHelper.SaveViewContentToPdf(@"C:\1.pdf", chart1);
}
}

public class MyClass
{
public MyClass()
{
var temp = new Dictionary<string, int>();
for (int i = 1; i < 10; i++)
{
temp.Add(Convert.ToString(0900 + i), i);
}
source1 = temp;
}

public Dictionary<string, int> source1
{
get;
set;
}
}

public class PdfXpsHelper
{
public static void SaveViewContentToPdf(string path, Visual viewbox)
{
MemoryStream lMemoryStream = new MemoryStream();
Package package = Package.Open(lMemoryStream, FileMode.Create);
XpsDocument doc = new XpsDocument(package);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
VisualsToXpsDocument vToXpsD = (VisualsToXpsDocument)writer.CreateVisualsCollator();

vToXpsD.Write(viewbox);
vToXpsD.EndBatchWrite();

doc.Close();
package.Close();

var pdfXpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(lMemoryStream);
PdfSharp.Xps.XpsConverter.Convert(pdfXpsDoc, path, 0);
}
}

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/