Chart for .NET / User's Guide / Printing / Printer Friendly Charts

In This Topic
    Printer Friendly Charts
    In This Topic

    Sometimes when you print you want to change the chart appearance according to the available printer. For example you may want to print a grayscale chart on a color printer to save ink or convert all solid colors on the chart to hatch pattern in order to increase the chart readability (on black and white printers colors with close intensity are not distinguishable). In such cases you may use the built in attribute converters allowing you to convert the current chart appearance to a printer friendly one.

     Using the NNodeTreeAttributeContverter

    The NNodeTreeAttributeConverter  provides and easy and yet powerful way to convert or modify all attributes in the chart to something else. The following code

    C#
    Copy Code
    INObjectConverter[] converters = new INObjectConverter[] 
      { 
      new NFillStyleToGrayScaleConverter(),
      new NStrokeStyleToGrayScaleConverter(),
      new NShadowStyleToGrayScaleConverter(),
      new NLightModelToGrayScaleConverter() };
      }
    
    NNodeTreeAttributeConverter grayScaleConverter = new NNodeTreeAttributeConverter();
    grayScaleConverter.Converters = converters;
    grayScaleConverter.Convert(chartControl.Document);
    

    Converts all the colors of all fill styles, stroke styles, shadow styles and lights in the control to a shade of gray (based on the intensity of the color).

     Creating Printer Friendly Charts

    In order to create printer friendly charts you must first replicate the component state and then use an attribute converter that prepares the chart for printing. The following code will create a printer friendly chart by replacing all solid fill styles to a black and white HatchStyle:

    C#
    Copy Code
    // create a duplicate of this chart control
    MemoryStream memoryStream = new MemoryStream();
    chartControl.Serializer.SaveControlStateToStream(memoryStream, PersistencyFormat.Binary, null);
    
    memoryStream.Seek(0, SeekOrigin.Begin);
    NChartControl chartControl = new NChartControl();
    chartControl.Serializer.LoadControlStateFromStream(memoryStream, PersistencyFormat.Binary, null);
    
    // convert the chart
    INObjectConverter[] converters = new INObjectConverter[] 
    {
       new NFillStyleColorToHatchConverter(),
       new NStrokeStyleToGrayScaleConverter(),
       new NShadowStyleToGrayScaleConverter(),
       new NLightModelToGrayScaleConverter() 
    };
    
    NNodeTreeAttributeConverter grayScaleConverter = new NNodeTreeAttributeConverter();
    grayScaleConverter.Converters = converters;
    grayScaleConverter.Convert(chartControl);
    
    // then print it
    chartControl.PrintManager.Print();
    
     Related Examples
    Windows Forms: Printing\Printed Chart Appearance

    See Also

    NFillStyleColorToHatchConverter | NStrokeStyleToGrayScaleConverter | NShadowStyleToGrayScaleConverter | NLightModelToGrayScaleConverter