Я хочу реализовать кнопку загрузки, где пользователь может сохранить диаграммы в формате PDF вместе с текстом описания.
Пример диаграммы
Вот моя функция GeneratePDF
/>
Код: Выделить всё
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)
}
И вот как я это называю.
Код: Выделить всё
React.useEffect(() => {
navigation.setOptions({
headerRight: () => (
)
})
Я пробовал использовать react-native-html-to-pdf и chart.js, но PDF-файл оказался пустым.
Подробнее здесь: https://stackoverflow.com/questions/797 ... -nativeexp