This is a migrated thread and some comments may be shown as answers.

Chart Colors on PDF Export

3 Answers 526 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 30 Oct 2018, 09:26 PM

My website has a dark theme so the chart has a black background with white text, but when it's exported to PDF the background color should be white and the text color should be black.  How do you set the colors of the chart to be different for when it's being exported to PDF?  

 

Thanks,
Rob

3 Answers, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
answered on 31 Oct 2018, 03:22 PM

I figured out how to do it.  You have to set the color on things like the legend to "currentColor" which tells it to use the color that's defined on the parent html element.  You can then set the text color to black in css for the .k-pdf-export class which is applied when it's exported.

Chart:

<kendo-chart [legend]="{labels: {color: 'currentColor'}}">
    <kendo-chart-area background="transparent"></kendo-chart-area>

    ...

</kendo-chart>

 

css:

.k-pdf-export .k-wdiget {
    color: #000;
}
0
Accepted
Dimiter Topalov
Telerik team
answered on 01 Nov 2018, 07:05 AM
Hello Rob,

You can customize the styling of the exported content via modifying the exportVisual options in accordance with your preference:

https://www.telerik.com/kendo-angular-ui/components/charts/chart/export-options/#toc-saving-charts-in-pdf

public exportChart(): void {
    const visual = this.chart.exportVisual({
        options: {
          chartArea: {
            background: '#fff'
          },
          legend: {
            labels: {
              color: '#000'
            }
          }
        }
    });
 
    exportPDF(visual, {
      paperSize: "A4",
      landscape: true
    }).then((dataURI) => {
      saveAs(dataURI, 'chart.pdf');
    });
  }

The options object follows the same structure as the Chart's root configuration object when configured via an inline options, provided as an object, as opposed to nested components (an more complex example, demonstrating this configuration approach is available in this demo).

Here is a runnable example illustrating the described approach for inverting the Chart colors when exported:

https://stackblitz.com/edit/angular-sqfreu-aqd6h6?file=app/app.component.ts

I hope this helps.

Regards,
Dimiter Topalov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Rob
Top achievements
Rank 1
answered on 01 Nov 2018, 01:14 PM

Hi Dimiter,

Thank you for your help, that accomplishes what I was looking for.  I had read that help doc on saving charts to pdf but it didn't mention that you could pass all of that in to the exportVisual method.

 

Thanks,
Rob

Tags
General Discussions
Asked by
Rob
Top achievements
Rank 1
Answers by
Rob
Top achievements
Rank 1
Dimiter Topalov
Telerik team
Share this question
or