PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Apr 26, 2018 5:24 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Fri Aug 08, 2014 6:18 am 
Offline

Joined: Fri Aug 08, 2014 6:02 am
Posts: 1
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);
}
}


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group