Wie kann ich ein Diagramm (Linie, Balken, Kreis ...) in React Native (Expo) in ein PDF-Format konvertieren? [geschlossenHTML

HTML-Programmierer
Anonymous
 Wie kann ich ein Diagramm (Linie, Balken, Kreis ...) in React Native (Expo) in ein PDF-Format konvertieren? [geschlossen

Post by Anonymous »

Ich habe **react-native-gifted-charts ** verwendet, um ein paar Diagramme in meiner **react-native expo **-Anwendung zu erstellen.
Ich möchte einen Download-Button implementieren, über den ein Benutzer die Diagramme zusammen mit etwas Beschreibungstext als PDF speichern kann.
Diagrammbeispiel
Hier ist meine GeneratePDF-Funktion

Code: Select all

const generatePDF = async () => {
setIsLoading(true);
try {
const html = `











const ctx = document.getElementById('myChart');

new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});



`;

const options = {
html,
fileName: `Testing`,
directory: `Testing`,
};

const file = await RNHTMLtoPDF.convert(options);

Alert.alert('Success', `PDF saved to ${file.filePath}`, [
{
text: 'OK',
onPress: () => navigation.popToTop()
}
]);

setCount(count + 1);
setIsLoading(false);
} catch (error) {
Alert.alert('Error', error.message)
}
};
Und hier nenne ich es.

Code: Select all

React.useEffect(() => {
navigation.setOptions({
headerRight: () => (

)
})
}, []);
Ich habe versucht, react-native-html-to-pdf und chart.js zu verwenden, aber das PDF kommt leer heraus.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post