DataVisualization Line Chart missing visible data - WPF

Jan 19, 2010 at 8:15 PM

Please help me to understand why a data series is not rendering on the chart even though the range of values used to label the X Axis seem to indicate knowledge of the supplied data series.

I want to understand how to utilize the Chart control within WPF in an entirely programmable way so for know, XML solutions will only confuse me :)

I have a simple class duplicated below that serves as my working example; it can be run by creating an instance of the class and invoking the 'PrintIt()' method.

The issue is that the chart is rendered to the printer but without the actual data points and connecting line.

Can some kind person please offer some advice as to what I am missing?

As you can tell my goal is simply to print the chart on paper (outside of the GUI).

Thanks in advance.



Sample Class Below


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Controls.DataVisualization.Charting;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Xps;
using System.Printing;
using System.Windows.Data;

namespace WpfGraphTest
    class LineGraphTest

        public void PrintIt()
            Visual chart = createChart();

            FixedDocument doc = new FixedDocument();
            FixedPage page = new FixedPage();
            PageContent pageContent = new PageContent();

            Canvas canvas = new Canvas();
            Canvas.SetLeft((UIElement)chart, 100);
            Canvas.SetTop((UIElement)chart, 200);

            PrintDocumentImageableArea area = null;
            XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(ref area);
            if (xpsdw != null)

        private Chart createChart()
            Chart chart = new Chart();
            chart.Name = "TheChart";
            chart.Title = "Title";
            chart.Width = 400;
            chart.Height = 400;
            chart.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            chart.Background = Brushes.White;

            LinearAxis xAxis = new LinearAxis() { Orientation = AxisOrientation.X, ShowGridLines = true, Title = "X Axis" };

            LinearAxis yAxis = new LinearAxis() { Interval = 10, Minimum = 0, Maximum = 100, Orientation = AxisOrientation.Y, ShowGridLines = true, Title = "Y Axis" };

            LineSeries lineSeries = new LineSeries();
            lineSeries.Title = "Series 1";
            lineSeries.DependentValuePath = "Value";
            lineSeries.IndependentValuePath = "Key";

            lineSeries.DependentRangeAxis = yAxis;

            KeyValuePair<int, int>[] lineSeriesData = new KeyValuePair<int, int>[] {
                new KeyValuePair<int, int>(0, 0),
                new KeyValuePair<int, int>(1, 20),
                new KeyValuePair<int, int>(4, 40)

            lineSeries.ItemsSource = lineSeriesData;


            return chart;

Jan 20, 2010 at 9:15 PM

Does anyone have any hints for me? Or is my question too dumb to bother with :)

I am very new to everything WPF. This control works for me when I'm using it for the screen; it is quite a mystery why the data points are not visible when I try to generate directly to paper.

Any ideas please share :)

Thanks in advance



Mar 3, 2010 at 1:48 PM


I got the same problem - I guess it is a result from the "revealing" animation of the chart.

You can notice when you load the chart in a program that it fades the points and lines in...

So you need to disable the animation which should be somehow possible with the VisualStateManager... well printing is a bit in the future for my project for now... but if you have a solution it would be nice if you share it :)

Mar 5, 2010 at 2:08 PM



Have you tried to do something like this:


PS: I dont know how to do this with the Chart.....


Nov 23, 2010 at 9:58 PM

Hello, somebody knows how to disable the chart animation with VisualStateManager? My XPS document can't show chart lines :(

Thank you!

Dec 14, 2010 at 2:31 PM


I have found this code :