TradingPal / react-native-highcharts

📈 Add Highcharts charts to react-native app for IOS and Android
https://github.com/TradingPal/react-native-highcharts
256 stars 158 forks source link

Use downloaded libraries instead of online libraries #7

Open minhquankq opened 7 years ago

minhquankq commented 7 years ago

When I inspect code of react-native-chartView.js, I saw that we use online libraries

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

that make the rendering slower. I'm not sure that are they cache or not, but the render delay 1s.

Can we use local libraries instead of online?

jonrh commented 7 years ago

I had noticed this as well (in the code & delay) and am in favour of having the needed dependencies be baked into the eventual React Native bundle JS file (if possible), i.e. no extra network requests. It would also be of benefit for offline apps. I suspect this might come down to licences.

I've been playing a bit around with the code and I believe that jQuery is not needed. As far as I can tell the only thing jQuery is used for as of now is to register a document ready callback. As seen here:

$(function () {
    Highcharts.stockChart('container', highchartConfigObject);
});

Without being 100% I think this could be replaced as such and no longer needing the jQuery dependency:

document.addEventListener("DOMContentLoaded", function() {
    Highcharts.chart('container', highchartConfigObject);
});
mmazzarolo commented 7 years ago

Hi everyone! Does anyone have any hints on how to use offline bundles instead?

jonrh commented 7 years ago

Update: Please ignore, will probably not work. See reply below.

@mmazzarolo One dirty way would be to modify the file react-native-ChartView.js. There you could swap out line 38

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

with:

<script>put the contents of the https://code.jquery.com/jquery-2.1.4.min.js file here</script>

You would then do this for all the Githubissues.

  • Githubissues is a development platform for aggregating issues.