<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vishwas R</title>
    <description>The latest articles on DEV Community by Vishwas R (@vishwas).</description>
    <link>https://dev.to/vishwas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F181797%2F6d791c42-6814-4bfd-abdd-0c12eb88d84c.jpeg</url>
      <title>DEV Community: Vishwas R</title>
      <link>https://dev.to/vishwas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vishwas"/>
    <language>en</language>
    <item>
      <title>Dynamic Highlighting of Weekends in CanvasJS Charts</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Thu, 20 Mar 2025 07:54:58 +0000</pubDate>
      <link>https://dev.to/vishwas/dynamic-highlighting-of-weekends-in-canvasjs-charts-226k</link>
      <guid>https://dev.to/vishwas/dynamic-highlighting-of-weekends-in-canvasjs-charts-226k</guid>
      <description>&lt;p&gt;Visualizing time-series data - such as financial charts, project timelines, or event trackers - often requires contextual markers like weekends or holidays to improve insights. &lt;a href="https://canvasjs.com/" rel="noopener noreferrer"&gt;CanvasJS charts&lt;/a&gt; offer the flexibility to dynamically highlight specific date ranges using stripLines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4u2jbvhbdq60y9h2w33q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4u2jbvhbdq60y9h2w33q.jpg" alt="CanvasJS JavaScript Chart with Weekend Highlighting" width="800" height="271"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Highlight Weekends/Holidays?
&lt;/h3&gt;

&lt;p&gt;Highlighting weekends or holidays on a chart can serve various purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Weekends&lt;/strong&gt; often have predictable patterns (e.g., reduced sales or web traffic).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Holidays&lt;/strong&gt; can cause atypical spikes or drops in data.&lt;/li&gt;
&lt;li&gt;  Highlighting these days helps users understand whether fluctuations are &lt;strong&gt;seasonal&lt;/strong&gt; or &lt;strong&gt;exceptional&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  StripLines to Highlight Weekends
&lt;/h3&gt;

&lt;p&gt;CanvasJS provides a flexible way to highlight specific regions on a chart using &lt;strong&gt;stripLines&lt;/strong&gt;, which are vertical or horizontal bands drawn across an axis. For a date-time axis (typically axisX in time-based charts), stripLines can be configured with value and endValue properties to span specific time ranges, such as an entire day.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Determine the Date Range&lt;/strong&gt;: Identify the minimum and maximum dates from your data or the visible viewport.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Identify Special Days&lt;/strong&gt;: Calculate weekend dates (Saturdays and Sundays) or retrieve holiday dates from a list.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Add StripLines&lt;/strong&gt;: Use stripLines to shade these days with customizable colors and opacity.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For most use cases, adding all stripLines initially is sufficient, as CanvasJS efficiently renders only those within the visible range. However, for large datasets or specific requirements, dynamic updates can optimize performance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addWeekendStripLines(chart, axis) {
    var startDate = chart.axisX[0].get("viewportMinimum"),
        endDate = chart.axisX[0].get("viewportMaximum"),
        currentDate = new Date(startDate);

    var stripLines = [];

    while (currentDate &amp;lt;= endDate) {
        if (currentDate.getDay() === 6) {
            // Saturday
            var weekendStart = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 0, 0, 0);
            var weekendEnd = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate() + 1, 23, 59, 59);

            stripLines.push({
                startValue: weekendStart,
                endValue: weekendEnd,
                color: "#ECEEF0",
                opacity: 0.5,
                label: "Weekend",
                labelAlign: "center",
                labelFontColor: "#333",
                labelBackgroundColor: "transparent"
            });
        }

        currentDate.setDate(currentDate.getDate() + 1);
    }

    axis.set("stripLines", stripLines);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can apply a similar technique for holidays by maintaining a list of holiday ranges and pushing stripLines for those periods.&lt;/p&gt;

&lt;h4&gt;
  
  
  Customization Tips
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Opacity:&lt;/strong&gt; Adjust the alpha channel in colors (e.g., #FFD1D180 → 80 = 50% opacity).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Labels:&lt;/strong&gt; Add labelPlacement: "inside" to display labels within striplines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Priority:&lt;/strong&gt; Order striplines array to overlay holidays on weekends.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/vishwas/embed/raNJvRo?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Using StripLines in CanvasJS, you can dynamically highlight weekends, holidays, or any date range to add context to time-series data. This method keeps your chart clean while emphasizing critical periods. Try adjusting colors and transparency to match your dashboard’s theme!&lt;/p&gt;

</description>
      <category>canvasjs</category>
      <category>javascript</category>
      <category>charts</category>
      <category>dataviz</category>
    </item>
    <item>
      <title>Browser Storage Types and Their Maximum Limits</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Tue, 18 Feb 2025 10:31:08 +0000</pubDate>
      <link>https://dev.to/vishwas/browser-storage-types-and-their-maximum-limits-174f</link>
      <guid>https://dev.to/vishwas/browser-storage-types-and-their-maximum-limits-174f</guid>
      <description>&lt;p&gt;Web applications often rely on browser storage to store and manage data locally. This table compares various browser storage types—like Cookies, LocalStorage, and IndexedDB—across popular browsers such as Chrome, Firefox, and Safari. Knowing the maximum storage limits for each browser helps developers select the most suitable storage method for their needs while ensuring optimal performance and user experience.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Storage Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Chrome/Edge&lt;/th&gt;
&lt;th&gt;Firefox&lt;/th&gt;
&lt;th&gt;Safari&lt;/th&gt;
&lt;th&gt;Opera&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cookies&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Small data files sent by a website and stored on the user's device, primarily used for session management and tracking.&lt;/td&gt;
&lt;td&gt;Approximately 4 KB per cookie, with a limit of around 20 cookies per domain.&lt;/td&gt;
&lt;td&gt;Approximately 4 KB per cookie, with a limit of around 20 cookies per domain.&lt;/td&gt;
&lt;td&gt;Approximately 4 KB per cookie, with a limit of around 20 cookies per domain.&lt;/td&gt;
&lt;td&gt;Approximately 4 KB per cookie, with a limit of around 20 cookies per domain.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;LocalStorage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Provides persistent storage that remains even after the browser is closed; data is stored as key-value pairs in string format.&lt;/td&gt;
&lt;td&gt;Typically 10 MB per origin. (&lt;a href="https://en.wikipedia.org/wiki/Web_storage" rel="noopener noreferrer"&gt;Wikipedia&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Typically 10 MB per origin. (&lt;a href="https://en.wikipedia.org/wiki/Web_storage" rel="noopener noreferrer"&gt;Wikipedia&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Typically 5 MB per origin. (&lt;a href="https://en.wikipedia.org/wiki/Web_storage" rel="noopener noreferrer"&gt;Wikipedia&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Typically 5 MB per origin. (&lt;a href="https://en.wikipedia.org/wiki/Web_storage" rel="noopener noreferrer"&gt;Wikipedia&lt;/a&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;SessionStorage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Similar to LocalStorage but scoped to the lifetime of the page session; data is cleared when the page session ends.&lt;/td&gt;
&lt;td&gt;Approximately 5 MB per origin. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Approximately 5 MB per origin. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Approximately 5 MB per origin. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Approximately 5 MB per origin. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;IndexedDB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A low-level API for storing large amounts of structured data, including files/blobs; useful for applications requiring complex data storage.&lt;/td&gt;
&lt;td&gt;Up to 60% of the total disk size per origin. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Up to 50% of free disk space, with a maximum of 2 GB per origin. (&lt;a href="https://medium.com/%40zaffarabbasmughal/browsers-support-and-limitation-towards-pwa-2e6c58cd16d5" rel="noopener noreferrer"&gt;medium.com&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Up to 20% of total disk space per origin; increases to 60% if saved as a web app. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Similar to Chrome, as Opera is based on Chromium.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cache Storage API&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Allows storage of request/response object pairs for efficient resource retrieval, primarily used by service workers for offline caching.&lt;/td&gt;
&lt;td&gt;Managed by the browser's storage management system; specific limits vary by browser and are typically substantial. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Managed by the browser's storage management system; specific limits vary by browser and are typically substantial. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Managed by the browser's storage management system; specific limits vary by browser and are typically substantial. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Managed by the browser's storage management system; specific limits vary by browser and are typically substantial. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;File System Access API&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Enables web applications to access and store files on the user's local file system with user consent; useful for applications requiring direct file manipulation.&lt;/td&gt;
&lt;td&gt;Managed by the browser's storage management system; specific limits vary by browser and are typically substantial. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Managed by the browser's storage management system; specific limits vary by browser and are typically substantial. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Managed by the browser's storage management system; specific limits vary by browser and are typically substantial. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Managed by the browser's storage management system; specific limits vary by browser and are typically substantial. (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Ultimately, knowing the storage capabilities and constraints of each browser helps developers make the best choice for their web applications. Whether you need simple key-value pairs or complex, offline-capable storage, this guide provides the foundation for effective storage management. By leveraging the right storage type for the job, you can avoid performance bottlenecks and enhance the user experience.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>cookies</category>
      <category>localstorage</category>
      <category>indexeddb</category>
    </item>
    <item>
      <title>Integrating CanvasJS Charts in Salesforce Lightning Aura Component</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Fri, 13 Dec 2024 11:50:53 +0000</pubDate>
      <link>https://dev.to/vishwas/integrating-canvasjs-charts-in-salesforce-lightning-aura-component-5gg9</link>
      <guid>https://dev.to/vishwas/integrating-canvasjs-charts-in-salesforce-lightning-aura-component-5gg9</guid>
      <description>&lt;p&gt;Visualizing data within Salesforce enhances user engagement and decision-making. A recent study showed that dashboards with interactive charts increase user adoption by 70%. This article guides you through seamlessly integrating &lt;a href="https://canvasjs.com/" rel="noopener noreferrer"&gt;CanvasJS charts&lt;/a&gt; into your Lightning Aura components for impactful data representation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4prosoaena1fnrz2b9vr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4prosoaena1fnrz2b9vr.png" alt="CanvasJS in Salesforce Lightning Aura Component" width="800" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Salesforce&lt;/li&gt;
&lt;li&gt;CanvasJS&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Steps to Create a Lightning App
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Create a New Lightning Application&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the Salesforce Developer Console.&lt;/li&gt;
&lt;li&gt;Navigate to File &amp;gt; New &amp;gt; Lightning Component.&lt;/li&gt;
&lt;li&gt;Provide a name for the component and a brief description.&lt;/li&gt;
&lt;li&gt;Click Submit.&lt;/li&gt;
&lt;li&gt;Save your component using File &amp;gt; Save or by pressing Ctrl + S.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Preview the Application&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the Preview button in the Developer Console (located in the upper-right corner).&lt;/li&gt;
&lt;li&gt;This will open the application in your browser.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Integrating the CanvasJS Library
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;CanvasJSLightningApp.app&lt;/strong&gt;&lt;br&gt;
This application serves as the container for the component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;aura:application&amp;gt;
    &amp;lt;c:CanvasJSLightningComponent /&amp;gt;
&amp;lt;/aura:application&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;CanvasJSLightningComponent.cmp&lt;/strong&gt;&lt;br&gt;
This component renders the chart. Ensure the ltng:require directive includes the correct paths to your static resources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;aura:component implements="flexipage:availableForAllPageTypes" access="global"&amp;gt;
    &amp;lt;ltng:require scripts="/resource/jquery,/resource/canvasjs" afterScriptsLoaded="{!c.renderChart}"/&amp;gt;
    &amp;lt;div aura:id="chartContainer" style="width: 100%; height: 360px;"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/aura:component&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;CanvasJSLightningComponentController.js&lt;/strong&gt;&lt;br&gt;
This controller includes the logic to render the CanvasJS chart.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;({
    renderChart : function(component, event, helper) {        
        new CanvasJS.Chart(component.find("chartContainer").getElement(), {
            title: {
                text: "CanvasJS Chart - Salesforce Lightning App"
            },
            data: [{
                type: "funnel",
                dataPoints: [
                    { y: 100, label: "Apple" },
                    { y: 63, label: "Orange" },
                    { y: 35, label: "Banana" },
                    { y: 15, label: "Mango" },
                    { y: 5, label: "Grape" }
                ]
            }]
        }).render();
    }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Static Resources:&lt;/strong&gt; The &lt;code&gt;ltng:require&lt;/code&gt; directive includes jQuery and CanvasJS as dependencies.&lt;br&gt;
&lt;strong&gt;Chart Rendering:&lt;/strong&gt; The &lt;code&gt;renderChart&lt;/code&gt; method initializes the CanvasJS chart within the chartContainer div.&lt;br&gt;
&lt;strong&gt;Chart Data:&lt;/strong&gt; Customize the dataPoints array to display the desired data.&lt;/p&gt;




&lt;h4&gt;
  
  
  Preview and Verify
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Save all files in the Developer Console.&lt;/li&gt;
&lt;li&gt;Open the application preview to verify the chart renders correctly.&lt;/li&gt;
&lt;li&gt;Adjust look &amp;amp; feel of chart as needed to fit your requirements.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This integration provides a dynamic way to visualize data using CanvasJS within Salesforce Lightning. Ensure all libraries are properly uploaded and referenced to avoid issues during deployment. For additional information, refer to the GitHub repository: &lt;a href="https://github.com/vishwas-r/CanvasJSLightningAuraApp" rel="noopener noreferrer"&gt;CanvasJS Lightning Aura App&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>canvasjs</category>
      <category>salesforce</category>
      <category>lwc</category>
      <category>javascriptlibraries</category>
    </item>
    <item>
      <title>Integrating CanvasJS with DataTables</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Tue, 01 Oct 2024 11:38:23 +0000</pubDate>
      <link>https://dev.to/vishwas/integrating-canvasjs-with-datatables-112n</link>
      <guid>https://dev.to/vishwas/integrating-canvasjs-with-datatables-112n</guid>
      <description>&lt;p&gt;&lt;a href="https://canvasjs.com/" rel="noopener noreferrer"&gt;CanvasJS&lt;/a&gt; is a JavaScript charting library that allows you to create interactive and responsive charts, while &lt;a href="https://datatables.net/" rel="noopener noreferrer"&gt;DataTables&lt;/a&gt; is a jQuery plugin that enhances HTML tables with advanced interaction controls like pagination, filtering, and sorting. Combining these two tools in a dashboard enables real-time data visualization, making it easier to analyze and interpret data trends and patterns through interactive and visually appealing charts that update dynamically based on the table data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhm2jwghj2ceq9cc7pt3w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhm2jwghj2ceq9cc7pt3w.jpg" alt="CanvasJS Chart with Datatables" width="800" height="592"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we’ll walk through the process of integrating CanvasJS with DataTables to create a dynamic pie chart that updates based on the data in the table. This example will use a simple HTML structure and JavaScript code to demonstrate the integration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before we begin, ensure you have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of HTML, CSS, and JavaScript.&lt;/li&gt;
&lt;li&gt;CanvasJS and DataTables libraries included in your project.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 1: Setting Up the HTML
&lt;/h4&gt;

&lt;p&gt;First, create an HTML file with a container for the chart and a table for the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div id="chartContainer" style="height: 370px; width: 100%;"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;table id="example" class="display" style="width:100%"&amp;gt;
  &amp;lt;thead&amp;gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;
      &amp;lt;th&amp;gt;Position&amp;lt;/th&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/thead&amp;gt;
  &amp;lt;tbody&amp;gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;td&amp;gt;Tiger Nixon&amp;lt;/td&amp;gt;
      &amp;lt;td&amp;gt;System Architect&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;td&amp;gt;Garrett Winters&amp;lt;/td&amp;gt;
      &amp;lt;td&amp;gt;Accountant&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
    &amp;lt;!-- Add more rows as needed --&amp;gt;
  &amp;lt;/tbody&amp;gt;
&amp;lt;/table&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Step 2: Creating the JavaScript File
&lt;/h4&gt;

&lt;p&gt;Create a script.js file and add the following code to initialize the DataTable and CanvasJS chart.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Create DataTable
var table = new DataTable('#dataTable');

// Create chart
var chart = new CanvasJS.Chart('chartContainer', {
        animationEnabled: true,
    theme: "light2",
    title: {
        text: 'Staff Count Per Position'
    },
    data: [
        {
            type: "pie",
          dataPoints: chartData(table)
        }
    ]
});
chart.render();

// On each draw, update the data in the chart
table.on('draw', function () {
    chart.options.data[0].dataPoints = chartData(table);
    chart.render();
});

function chartData(table) {
    var counts = {};

    // Count the number of entries for each position
    table
        .column(1, { search: 'applied' })
        .data()
        .each(function (val) {
            if (counts[val]) {
                counts[val] += 1;
            }
            else {
                counts[val] = 1;
            }
        });

    return Object.entries(counts).map((e) =&amp;gt; ({
        label: e[0],
        y: e[1]
    }));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTML Structure:&lt;/strong&gt; The HTML file includes a container for the chart (chartContainer) and a table (example) with sample data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DataTable Initialization:&lt;/strong&gt; The DataTable is initialized using the DataTable constructor.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CanvasJS Chart Initialization:&lt;/strong&gt; A new CanvasJS chart is created with the specified options, including the chart type (pie) and data points.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Data Update:&lt;/strong&gt; The draw event of the DataTable is used to update the chart data points whenever the table is redrawn. The chartData function calculates the number of entries for each position and updates the chart accordingly.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Step 3: Test and Debug
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Open the HTML file in a web browser: Ensure that the chart and table are displayed correctly.&lt;/li&gt;
&lt;li&gt;Check for errors: Open the browser’s developer console to check for any JavaScript errors.&lt;/li&gt;
&lt;li&gt;Verify dynamic updates: Add or remove rows from the table and ensure that the chart updates accordingly.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://jsfiddle.net/vishwas_r/2rd9bt7j/" rel="noopener noreferrer"&gt;
      jsfiddle.net
    &lt;/a&gt;
&lt;/div&gt;



&lt;p&gt;By following these steps, you have successfully integrated CanvasJS with DataTables to create a dynamic pie chart that updates based on the data in the table. This integration allows you to visualize data in real-time, making it easier to analyze and understand the information presented in the DataTable. Feel free to customize the chart and table as needed for your specific use case. Happy coding!&lt;/p&gt;

</description>
      <category>canvasjs</category>
      <category>datatables</category>
      <category>javascript</category>
      <category>charts</category>
    </item>
    <item>
      <title>Exploring CDN Links for CanvasJS Charts and Stockcharts</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Mon, 28 Aug 2023 06:27:10 +0000</pubDate>
      <link>https://dev.to/vishwas/exploring-cdn-links-for-canvasjs-charts-and-stockcharts-2h62</link>
      <guid>https://dev.to/vishwas/exploring-cdn-links-for-canvasjs-charts-and-stockcharts-2h62</guid>
      <description>&lt;p&gt;When it comes to creating interactive and visually appealing charts for web applications, &lt;a href="https://canvasjs.com/" rel="noopener noreferrer"&gt;CanvasJS&lt;/a&gt; is a popular charting library that offer a wide range of charts for your application. CanvasJS Charts &amp;amp; StockCharts enable developers to showcase data in a comprehensible manner, making it easier for users to grasp insights. To incorporate these libraries into your web project seamlessly, CDN (Content Delivery Network) links can be incredibly useful. Below is a list of CDN links for both CanvasJS Charts and Stockcharts.&lt;/p&gt;

&lt;h3&gt;
  
  
  CanvasJS Charts CDN Links:
&lt;/h3&gt;

&lt;p&gt;CanvasJS Charts provides a variety of chart types and interactive features. To integrate CanvasJS Charts into your web application, you can use the following CDN link:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdn.canvasjs.com/ga/canvasjs.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdn.jsdelivr.net/npm/@canvasjs/charts/canvasjs.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://www.unpkg.com/@canvasjs/charts/canvasjs.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simply include one of the above mentioned script tag inside head-section of your HTML file, and you'll have access to the CanvasJS Charts library.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stockcharts CDN Links:
&lt;/h3&gt;

&lt;p&gt;Stockcharts is specifically designed for creating financial and stock market-related charts. If you're looking to visualize stock data in your application, you can use the following CDN link:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdn.canvasjs.com/ga/canvasjs.stock.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdn.jsdelivr.net/npm/@canvasjs/stockcharts/canvasjs.stock.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://www.unpkg.com/@canvasjs/stockcharts/canvasjs.stock.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By including one of the the script-tag in your HTML, you'll be able to leverage the capabilities of the Stockcharts library for displaying stock market data. &lt;/p&gt;

&lt;h3&gt;
  
  
  Why Use CDN Links?
&lt;/h3&gt;

&lt;p&gt;CDN links offer several advantages when integrating external libraries into your web projects. Here are a few reasons why using CDN links for CanvasJS Charts and Stockcharts can be beneficial:&lt;/p&gt;

&lt;h4&gt;
  
  
  Efficiency:
&lt;/h4&gt;

&lt;p&gt;CDN links allow you to load the libraries from distributed servers, reducing the load on your own server and improving page load times.&lt;/p&gt;

&lt;h4&gt;
  
  
  Easy Updates:
&lt;/h4&gt;

&lt;p&gt;When a library is updated, the CDN link automatically serves the latest version to your application, ensuring that you're always using the most up-to-date features and fixes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Simplicity:
&lt;/h4&gt;

&lt;p&gt;Integrating libraries through CDN links is a straightforward process. You only need to add a single script tag to your HTML, saving you from downloading and managing the library files.&lt;/p&gt;

&lt;h4&gt;
  
  
  Global Availability:
&lt;/h4&gt;

&lt;p&gt;CDN links are hosted on servers around the world, improving accessibility for users across different regions.&lt;/p&gt;

&lt;p&gt;Utilizing CDN links for CanvasJS Charts and Stockcharts is a convenient way to enhance your web application with interactive and informative charts. By including the provided CDN links in your HTML code, you can harness the power of these libraries without the hassle of manual installation. This approach ensures that your application benefits from the latest features and improvements while maintaining optimal performance. Happy charting!&lt;/p&gt;

</description>
      <category>canvasjs</category>
      <category>cdn</category>
      <category>javascript</category>
      <category>libraries</category>
    </item>
    <item>
      <title>Convert HTML Form Data into PDF in PHP</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Wed, 29 Mar 2023 07:14:10 +0000</pubDate>
      <link>https://dev.to/vishwas/convert-html-form-data-into-pdf-in-php-50lg</link>
      <guid>https://dev.to/vishwas/convert-html-form-data-into-pdf-in-php-50lg</guid>
      <description>&lt;p&gt;PHP is a server-side programming language that is widely used for web development. One of the most common use cases of PHP is to process and store form data submitted by users. In many cases, it is necessary to convert the form data into a more usable format, such as a PDF document. In this article, lets explore how to use PHP to convert form data to PDF.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Install a PDF library
&lt;/h2&gt;

&lt;p&gt;The first step is to install a PHP library that can be used to generate PDF documents. There are several popular libraries available, such as TCPDF, FPDF, and mPDF. For this article, we will be using mPDF, which is a free and open-source library that is widely used for generating PDF documents in PHP.&lt;br&gt;
To install mPDF, you can download the latest version from the &lt;a href="https://github.com/mpdf/mpdf"&gt;Github&lt;/a&gt; (&lt;a href="https://github.com/mpdf/mpdf"&gt;https://github.com/mpdf/mpdf&lt;/a&gt;) or using composer and copy the folder to your web server.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Create a form
&lt;/h2&gt;

&lt;p&gt;The next step is to create a form that will allow users to input the data that will be converted to a PDF. In this example, we will create a simple form that collects the user's name, email address, and message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form method="post" action="process_form.php"&amp;gt;
    &amp;lt;label&amp;gt;Name:&amp;lt;/label&amp;gt;
    &amp;lt;input type="text" name="name"&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;label&amp;gt;Email:&amp;lt;/label&amp;gt;
    &amp;lt;input type="email" name="email"&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;label&amp;gt;Message:&amp;lt;/label&amp;gt;
    &amp;lt;textarea name="message"&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;input type="submit" value="Submit"&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Process the form data
&lt;/h2&gt;

&lt;p&gt;Once the form has been submitted, the form data must be processed and converted into a PDF document. To do this, we will create a PHP script called process_form.php.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

$path = (getenv("MPDF_ROOT")) ? getenv("MPDF_ROOT") : __DIR__;
require_once $path . "/vendor/autoload.php";

$pdfcontent = '&amp;lt;table class="form-data"&amp;gt;&amp;lt;thead&amp;gt;&amp;lt;tr&amp;gt; &amp;lt;/tr&amp;gt;&amp;lt;/thead&amp;gt;&amp;lt;tbody&amp;gt;';

foreach($_POST as $key =&amp;gt;$value){
    $pdfcontent .= "&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;" . ucwords(str_replace("_", " ",$key)) . "&amp;lt;/td&amp;gt;:&amp;lt;td&amp;gt;" . $value . "&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;";
}
$pdfcontent .= "&amp;lt;/tbody&amp;gt;&amp;lt;/table&amp;gt;";

$mpdf = new \Mpdf\Mpdf();
$mpdf-&amp;gt;WriteHTML(utf8_encode($pdfcontent));
$mpdf-&amp;gt;Output('formdata.pdf', 'D');

?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The process_form.php script first includes the mPDF library using the require_once statement. It then retrieves the form data using the $_POST superglobal array. With the posted data, it creates a HTML table. The script then creates a new mPDF object, write the HTML content, and outputs the form data to the PDF document. Finally, it lets you download the generated PDF by passing 'D' as a parameter in the Output method.&lt;/p&gt;

</description>
      <category>mpdf</category>
      <category>php</category>
      <category>form</category>
      <category>programming</category>
    </item>
    <item>
      <title>Data Visualization using CanvasJS in Django Apps</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Fri, 17 Feb 2023 07:04:26 +0000</pubDate>
      <link>https://dev.to/vishwas/data-visualization-using-canvasjs-in-django-apps-2mip</link>
      <guid>https://dev.to/vishwas/data-visualization-using-canvasjs-in-django-apps-2mip</guid>
      <description>&lt;p&gt;Data visualization is the process of representing data in a graphical or pictorial format to understand and interpret data better. In today's digital age, web applications are the primary medium for information exchange. Therefore, it's essential to integrate data visualization into web applications to make them more effective.&lt;/p&gt;

&lt;p&gt;In this article, we'll explore how to integrate &lt;a href="https://canvasjs.com/python-charts/" rel="noopener noreferrer"&gt;CanvasJS Python chart&lt;/a&gt; into Django applications to create interactive and visually appealing data visualizations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21tmqshq05aozpol7agv.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21tmqshq05aozpol7agv.jpeg" alt="CanvasJS Python Line Chart" width="800" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;We assume that you have a basic understanding of Django and have already set up a Django project. We will also assume that you have installed the latest version of CanvasJS by downloading the library from the official website.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a Django App
&lt;/h3&gt;

&lt;p&gt;First, create a new Django app within your project by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py startapp charts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new directory called "charts" in your project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a View
&lt;/h3&gt;

&lt;p&gt;Next, create a view in the "charts/views.py" file to render the chart on a web page. Here is a sample view that creates a line chart using the CanvasJS library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.shortcuts import render

def chart(request):
    dataPoints = [
        {"x": 10, "y": 21},
        {"x": 20, "y": 25},
        {"x": 30, "y": 20},
        {"x": 40, "y": 35},
        {"x": 50, "y": 38},
        {"x": 60, "y": 45},
        {"x": 70, "y": 50},
        {"x": 80, "y": 55},
        {"x": 90, "y": 60},
        {"x": 100, "y": 58}
    ]
    return render(request, 'index.html', {'dataPoints': dataPoints})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This view creates a list of datapoints and passes it to the chart template using the render() function. Note that we are using the "index.html" template where chart is rendered.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a template
&lt;/h3&gt;

&lt;p&gt;Now create the "index.html" template in the "charts/templates/charts" directory. This template will contain the HTML and JavaScript code to render the chart using the CanvasJS library. Here is a sample template that creates a line chart:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% load static %}
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
&amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&amp;gt;
&amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;
&amp;lt;script src="https://canvasjs.com/assets/script/canvasjs.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;
window.onload = function () {
    var chart = new CanvasJS.Chart("chartContainer", {
        theme: "light1", // "light2", "dark1", "dark2"
        animationEnabled: false, // change to true                
        title:{
            text: "Python Line Chart"
        },
        data: [{
            // Change type to "bar", "area", "spline", "pie",etc.
            type: "line",
            dataPoints: {{ data_points | safe }}
        }]
    });
    chart.render();
}
&amp;lt;/script&amp;gt;    
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div id="chartContainer" style="width: 100%; height: 360px;"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configure URLs &amp;amp; Run the Application
&lt;/h3&gt;

&lt;p&gt;Finally, add a URL to the "charts/urls.py" file to map the "chart" view to a URL. Here is a sample URL configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the Django server &lt;code&gt;python manage.py runserver&lt;/code&gt;. Navigate to "&lt;a href="http://localhost:8000/charts/" rel="noopener noreferrer"&gt;http://localhost:8000/charts/&lt;/a&gt;" in your web browser, and you should see a line chart generated by the CanvasJS library.&lt;/p&gt;

&lt;p&gt;Github: &lt;a href="https://github.com/vishwas-r/CanvasJS-Samples/tree/main/canvasjs-django-sample" rel="noopener noreferrer"&gt;https://github.com/vishwas-r/CanvasJS-Samples/tree/main/canvasjs-django-sample&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>Build Interactive Analytical Dashboard in Django</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Tue, 14 Feb 2023 12:40:48 +0000</pubDate>
      <link>https://dev.to/vishwas/build-interactive-analytical-dashboard-in-django-1ffl</link>
      <guid>https://dev.to/vishwas/build-interactive-analytical-dashboard-in-django-1ffl</guid>
      <description>&lt;p&gt;Django is a powerful Python Web Framework that makes building web applications and dashboards a breeze. There are open-source dashboards built with Django that come with modern UI Kits, and developers can create analytic dashboards in a Django app. In this article, let's explore how to build a beautiful dashboard in Django using Bootstrap, &lt;a href="https://canvasjs.com/python-charts/" rel="noopener noreferrer"&gt;CanvasJS Python Charts&lt;/a&gt; and a few other tools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmo4cmirykz4ab7h26m9e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmo4cmirykz4ab7h26m9e.png" alt="Django Dashboard using CanvasJS Python Charts" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Setup
&lt;/h2&gt;

&lt;p&gt;Create a new Django project. And create a new app within the project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;django-admin startproject dashboard
python manage.py startapp charts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create View
&lt;/h2&gt;

&lt;p&gt;Create a new file in the charts app called views.py. In this file, we'll define the view that will render our dashboard. Here's an example view that renders a template called index.html&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.shortcuts import render

def dashboard(request):
    return render(request, 'index.html')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create Template
&lt;/h2&gt;

&lt;p&gt;Create a new file in the charts/templates directory called dashboard.html. Define the layout of the dashboard using Bootstrap.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container-fluid"&amp;gt;
    &amp;lt;div class="row"&amp;gt;
        &amp;lt;nav class="col-md-2 d-none d-md-block bg-light sidebar"&amp;gt;
            &amp;lt;!-- Sidebar content goes here --&amp;gt;
        &amp;lt;/nav&amp;gt;

        &amp;lt;main class="col-md-9 ms-sm-auto col-lg-10 px-md-4"&amp;gt;
            &amp;lt;!-- Main content goes here --&amp;gt;
        &amp;lt;/main&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add Charts to the Dashboard
&lt;/h2&gt;

&lt;p&gt;CanvasJS is a powerful charting library that lets you create interactive charts for dashboards. To add CanvasJS charts to the project, download the library and include it in the template.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download the library from CanvasJS website.&lt;/li&gt;
&lt;li&gt;Extract the files to 'charts/static' folder.&lt;/li&gt;
&lt;li&gt;Include canvasjs.min.js in the template.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="{% static canvasjs.min.js' %}"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create Charts
&lt;/h3&gt;

&lt;p&gt;Now, that CanvasJS is included in the template, you can start creating different of charts like line, column, pie, etc. to show them in the dashboard.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* index.html */
&amp;lt;div id="chartContainer" style="width: 100%; height: 360px;"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;script&amp;gt;
    window.onload = function () {
        var chart = new CanvasJS.Chart("chartContainer", {
            title:{
                text: "Column Chart"
            },
            data: [{
                dataPoints: {{ datapoints | safe }}
        });
        chart.render();
    }
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the view to return the data for the chart.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* views.py */
from django.http import HttpResponse
from django.shortcuts import render
from django.template import loader

def index(request):
    datapoints= [
        { "label": "Jan", "y": 10000 },
        { "label": "Feb", "y": 30162 },
        { "label": "Mar", "y": 26263 },
        { "label": "Apr", "y": 18394 },
        { "label": "May", "y": 18287 },
        { "label": "Jun", "y": 28682 },
        { "label": "Jul", "y": 31274 },
        { "label": "Aug", "y": 33259 },
        { "label": "Sep", "y": 25849 },
        { "label": "Oct", "y": 24159 },
        { "label": "Nov", "y": 32651 },
        { "label": "Dec", "y": 31984 }
    ]
    return render(request, 'index.html', { "datapoints" : datapoints })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Customize the Dashboard
&lt;/h2&gt;

&lt;p&gt;Now that you have added one chart to the dashboard, add few more charts and customize the look and feel of the charts to match your dashboard. You can change the color &amp;amp; font-family of all the textual content of the chart to match it with the theme of dashboard.&lt;/p&gt;

&lt;p&gt;Github Link: &lt;a href="https://github.com/vishwas-r/Django-Dashboard-using-CanvasJS-Python-Charts" rel="noopener noreferrer"&gt;https://github.com/vishwas-r/Django-Dashboard-using-CanvasJS-Python-Charts&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>angular</category>
      <category>frontend</category>
      <category>api</category>
    </item>
    <item>
      <title>How to Add CanvasJS Charts to your Android App?</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Thu, 15 Sep 2022 08:41:35 +0000</pubDate>
      <link>https://dev.to/vishwas/how-to-add-canvasjs-charts-to-your-android-app-2d36</link>
      <guid>https://dev.to/vishwas/how-to-add-canvasjs-charts-to-your-android-app-2d36</guid>
      <description>&lt;p&gt;Android WebView is an android UI widget which is used to open any web URL or load html data.  WebView is used to show web page in android activity. In simple words, Android WebView is a View that displays web pages. In this tutorial lets see how to add &lt;a href="https://canvasjs.com/"&gt;CanvasJS charts&lt;/a&gt; to android app.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create a new project in Android Studio
&lt;/h2&gt;

&lt;p&gt;Create a new project with empty activity.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1jvkodjo1l01t2ihlqwj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1jvkodjo1l01t2ihlqwj.png" alt="Android Studio New Project with Empty Activity" width="800" height="579"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Add Asset Folder &amp;amp; Create HTML file
&lt;/h2&gt;

&lt;p&gt;Add asset folder in the newly created app &amp;amp; create html file in the folder, let's call it as "column chart.html". Paste the following code in the html file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE HTML&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;script&amp;gt;
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
theme: "light1", // "light2", "dark1", "dark2"
animationEnabled: true, // change to true
title:{
text: "Basic Column Chart"
},
data: [{
// Change type to "bar", "area", "spline", "pie",etc.
type: "column",
dataPoints: [
{ label: "apple",  y: 10  },
{ label: "orange", y: 15  },
{ label: "banana", y: 25  },
{ label: "mango",  y: 30  },
{ label: "grape",  y: 28  }
]
}]
});
chart.render();
}
&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;div id="chartContainer" style="height: 370px; width: 100%;"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;script src="./canvasjs.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Download &amp;amp; save canvasjs.min.js file in the assets folder. You can download CanvasJS library from their &lt;a href="https://canvasjs.com/download-html5-charting-graphing-library/"&gt;official download page&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Create HTML Activity
&lt;/h2&gt;

&lt;p&gt;By default, android studio would create activity_main.xml. Update the code of that file with the below one which creates a layout with webview.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"&amp;gt;

    &amp;lt;WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/&amp;gt;
&amp;lt;/LinearLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Update the Activity &amp;amp; Load HTML File
&lt;/h2&gt;

&lt;p&gt;In MainActivity.java, enable JavaScript for webview &amp;amp; load html file that you saved in assets folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.canvasjs.charts;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView canvasJSChartView = findViewById(R.id.webView);
        canvasJSChartView.setWebViewClient(new WebViewClient());

        canvasJSChartView.getSettings().setJavaScriptEnabled(true); //Enable Javascript for WebView


        canvasJSChartView.loadUrl("file:///android_asset/column chart.html");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's try to run your application. To run the app from android studio, open one of your project's activity files, select the device (if you have connected android device to your machine) / emulator device and click Run. Running the project should show you a CanvasJS column chart.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh1y4b4y4ldpjac4kxhx1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh1y4b4y4ldpjac4kxhx1.png" alt="CanvasJS Column Chart in Android App" width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Download Sample from &lt;a href="https://github.com/vishwas-r/CanvasJS-Samples/tree/main/canvasjs-android-sample"&gt;Github&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>canvasjs</category>
      <category>android</category>
      <category>webview</category>
    </item>
    <item>
      <title>How to add title to Markdown Links &amp; Images?</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Thu, 11 Aug 2022 05:49:17 +0000</pubDate>
      <link>https://dev.to/vishwas/how-to-add-title-to-markdown-links-images-41pa</link>
      <guid>https://dev.to/vishwas/how-to-add-title-to-markdown-links-images-41pa</guid>
      <description>&lt;p&gt;It's very important to add title to links &amp;amp; images. But in many blogs / websites, they accept markdown &amp;amp; not everyone are aware of or it's not so easy to find how to add title in markdown content. But it's pretty simple to add title in markdown content. Passing a string along with the link or image works in such scenario. Below is an example.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Add title to the links
[Open Google](https://google.com/ "Open Google")

//Add title to images
![alt text](image-url.png "Image Title")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Unfortunately, not all websites accepts &amp;amp; shows title. Some of them ignores the string passed whereas it works on GitHub. Many md cheat-sheets miss out adding this but seems helpful.&lt;/p&gt;

</description>
      <category>tip</category>
      <category>markdown</category>
      <category>html</category>
    </item>
    <item>
      <title>Add Interactive Angular Charts to ng-bootstrap Components</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Thu, 04 Aug 2022 10:21:28 +0000</pubDate>
      <link>https://dev.to/vishwas/add-interactive-angular-charts-to-ng-bootstrap-components-15hg</link>
      <guid>https://dev.to/vishwas/add-interactive-angular-charts-to-ng-bootstrap-components-15hg</guid>
      <description>&lt;p&gt;In this Angular 14 Chart tutorial, we will learn how to add charts to display data within ng-bootstrap tabs. A chart is basically a graphical representation of data, they summarize large data or information in a visual easy-to-understand manner. Being a web-designer / developer, one would obviously work on dashboard at some point of time. Dashboards gives much information with the help of charts. In this tutorial, I'm showing how to add &lt;a href="https://canvasjs.com/docs/charts/integration/angular/"&gt;CanvasJS chart&lt;/a&gt; in &lt;a href="https://ng-bootstrap.github.io/#/components/nav/overview"&gt;ng-bootstrap navs&lt;/a&gt; (tabs). I've built the app in Angular 14 but CanvasJS &amp;amp; ng-bootstrap works across multiple versions of angular. CanvasJS is robust charting library for web designers &amp;amp; developers. Chart component supports more than 30 chart types &amp;amp; are responsive, interactive, easy to customize &amp;amp; allows you to create beautiful charts that can match your webpage / application design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This tutorial was made using the latest versions at the time of writing:&lt;br&gt;
• Angular: v14.0.0&lt;br&gt;
• Ng-bootstrap: v13.0.0&lt;br&gt;
• CanvasJS Charts: v3.6.7&lt;/p&gt;
&lt;h2&gt;
  
  
  Create Angular App &amp;amp; Add ng-bootstrap
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Create Angular Project
&lt;/h3&gt;

&lt;p&gt;Create a fresh angular project using &lt;a href="https://angular.io/cli"&gt;Angular CLI&lt;/a&gt;. Ignore this step if you already have an app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new angular-bootstrap-charts

? Would you like to add Angular routing? Yes
? Which stylesheet format would you like to use? CSS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Add ng-bootstrap &amp;amp; CanvasJS angular chart components to the Project
&lt;/h3&gt;

&lt;p&gt;Once the angular project is created, add ng-bootstrap &amp;amp; CanvasJS angular charts to your project. ng-bootstrap can be added either using Angular CLI way or manually you can just perform 'npm install package-name'. Below are the syntaxes for both the approaches.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Angular CLI Way */
ng add @ng-bootstrap/ng-bootstrap

/* Manual Way */
npm install @ng-bootstrap/ng-bootstrap --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And CanvasJS angular charts can be downloaded from their &lt;a href="https://canvasjs.com/"&gt;official site&lt;/a&gt; (npm package is not the official one) &amp;amp; save it in assets folder to import to the project.&lt;/p&gt;

&lt;p&gt;Once the package is installed, let's import the module &amp;amp; register it. Open app.module.ts file &amp;amp; register the module.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* app.module.ts */
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';

import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

import * as CanvasJSAngularChart from '../assets/canvasjs.angular.component';
var CanvasJSChart = CanvasJSAngularChart.CanvasJSChart;

@NgModule({
  declarations: [
    AppComponent,
    CanvasJSChart
  ],
  imports: [
    BrowserModule,
    NgbModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add Bootstrap Nav (Tabs) Component
&lt;/h2&gt;

&lt;p&gt;To keep it simple, let's add &lt;a href="https://valor-software.com/ngx-bootstrap/#/components/tabs?tab=overview"&gt;bootstrap tabs&lt;/a&gt; to the app. You can consider adding any bootstrap component like modal, accordion, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Add Bootstrap Navs
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul ngbNav #nav="ngbNav" class="nav-tabs"&amp;gt;
  &amp;lt;li [ngbNavItem]="1"&amp;gt;
    &amp;lt;a ngbNavLink&amp;gt;Line Chart&amp;lt;/a&amp;gt;
    &amp;lt;ng-template ngbNavContent&amp;gt;
    &amp;lt;/ng-template&amp;gt;
  &amp;lt;/li&amp;gt;
  .
  .
  .
&amp;lt;/ul&amp;gt;

&amp;lt;div [ngbNavOutlet]="nav" class="mt-2"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Add Chart to the Nav
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul ngbNav #nav="ngbNav" class="nav-tabs"&amp;gt;
  &amp;lt;li [ngbNavItem]="1"&amp;gt;
    &amp;lt;a ngbNavLink&amp;gt;Line Chart&amp;lt;/a&amp;gt;
    &amp;lt;ng-template ngbNavContent&amp;gt;
      &amp;lt;canvasjs-chart
      [options]="lineChartOptions"
      [styles]="{ width: '100%', height: '360px' }"
      &amp;gt;&amp;lt;/canvasjs-chart&amp;gt;
    &amp;lt;/ng-template&amp;gt;
  &amp;lt;/li&amp;gt;
  .
  .
  .
&amp;lt;/ul&amp;gt;

&amp;lt;div [ngbNavOutlet]="nav" class="mt-2"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Show chart only in Active Tabs
&lt;/h3&gt;

&lt;p&gt;In tabs, content of active tabs will be shown while the content inactive tabs will be hidden. Hence, conditional rendering is required so that charts in inactive tabs are not rendered. To so do you can use keep a flag that keeps toggling when a tab is visible or hidden. Based on the flag, you can render the chart.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul ngbNav #nav="ngbNav" class="nav-tabs" (shown)="navChangeEvent($event)" (hidden)="navHiddenEvent($event)"&amp;gt;
  &amp;lt;li [ngbNavItem]="1"&amp;gt;
    &amp;lt;a ngbNavLink&amp;gt;Line Chart&amp;lt;/a&amp;gt;
    &amp;lt;ng-template ngbNavContent&amp;gt;
      &amp;lt;canvasjs-chart
      *ngIf="showChart"
      [options]="lineChartOptions"
      (chartInstance)="getChartInstance($event)"
      [styles]="{ width: '100%', height: '360px' }"
      &amp;gt;&amp;lt;/canvasjs-chart&amp;gt;
    &amp;lt;/ng-template&amp;gt;
  &amp;lt;/li&amp;gt;
  .
  .
  .
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe src="https://stackblitz.com/edit/angular-charts-ng-bootstrap-tabs?" width="100%" height="500"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;At the time of writing this article, CanvasJS v3.6.7 was used in Angular 14 project. However, CanvasJS charts work across all versions of Angular. If you are new to CanvasJS angular charts or CanvasJS API or need a refresher, I would recommend reading the &lt;a href="https://canvasjs.com/docs/charts/basics-of-creating-html5-chart/"&gt;CanvasJS Charts documentation&lt;/a&gt;. And for ng-bootstrap, check out this &lt;a href="https://ng-bootstrap.github.io/#/getting-started"&gt;documentation page&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>canvasjs</category>
      <category>angular</category>
      <category>charts</category>
      <category>bootstrap</category>
    </item>
    <item>
      <title>How to Build Drill Down Chart in Angular?</title>
      <dc:creator>Vishwas R</dc:creator>
      <pubDate>Wed, 20 Jul 2022 08:04:00 +0000</pubDate>
      <link>https://dev.to/vishwas/how-to-build-drill-down-chart-in-angular-4067</link>
      <guid>https://dev.to/vishwas/how-to-build-drill-down-chart-in-angular-4067</guid>
      <description>&lt;p&gt;Drill-down charts are widely used to show data in depth with additional information. Drill-down charts shows relation between parent-child data / chart. For example: A chart  can show yearly sales data (2010, 2011, 2012,...) and once you click on any of the year, it shows monthly / quarterly data of that particular year. In this article, let me brief how to create drill-down chart in angular using CanvasJS angular chart.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://canvasjs.com/docs/charts/integration/angular/"&gt;CanvasJS Angular Charts&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Add CanvasJS directives to your project
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Download CanvasJS from &lt;a href="https://canvasjs.com/download-html5-charting-graphing-library/"&gt;this link&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Add the angular chart component files to your project (canvasjs.min.js &amp;amp; canvasjs.angular.component.js).&lt;/li&gt;
&lt;li&gt;Register CanvasJS module
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgModule } from '@angular/core';
import * as CanvasJSAngularChart from '../assets/canvasjs.angular.component';
var CanvasJSChart = CanvasJSAngularChart.CanvasJSChart;

@NgModule({
  declarations: [
    AppComponent,
    CanvasJSChart
  ],
})
export class AppModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Refer &lt;a href="https://canvasjs.com/docs/charts/integration/angular/"&gt;CanvasJS Angular Integration&lt;/a&gt; section for more info / troubleshooting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Structuring Drill-Down Data
&lt;/h2&gt;

&lt;p&gt;CanvasJS accepts data in JSON format. That doesn't mean you have to store data in JSON file always. It simply means data has to be parsed to JSON format before passing it to chart options. The data can either be read from JSON / XML / CSV files or from a local JavaScript variable.&lt;br&gt;
To build drill-down chart, we need to have parent(yearly) &amp;amp; child(quarterly) data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yearlyData: [{
  cursor: 'pointer',
  dataPoints: [
    {
      label: "2019",
      y: 191630,
      name: "2019",
      color: '#f2c80f'
    }, {
      label: "2020",
      y: 203770,
      name: "2020",
      color: '#fc625e'
    }, {
      label: "2021",
      y: 193700,
      name: "2021",
      color: '#01b8aa'
    }]
}],
drilldownData: {
    '2019': [{
      color: "#f2c80f",
      dataPoints: [
        { label: 'Q1', y: 48980 },
        { label: 'Q2', y: 42690 },
        { label: 'Q3', y: 46980 },
        { label: 'Q4', y: 52980 }
      ]
    }],
    '2020': [{
      color: '#fc625e',
      dataPoints: [
        { label: 'Q1', y: 51780 },
        { label: 'Q2', y: 48590 },
        { label: 'Q3', y: 52500 },
        { label: 'Q4', y: 50900 }
      ]
    }],
    '2021': [{
      color: '#01b8aa',
      dataPoints: [
        { label: 'Q1', y: 42600 },
        { label: 'Q2', y: 44960 },
        { label: 'Q3', y: 46160 },
        { label: 'Q4', y: 48240 }
      ]
    }]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Perform Drill Down on Click
&lt;/h2&gt;

&lt;p&gt;Bind &lt;a href="https://canvasjs.com/docs/charts/chart-options/data/click/"&gt;click event&lt;/a&gt; to datapoints. &lt;a href="https://canvasjs.com/docs/charts/basics-of-creating-html5-chart/updating-chart-options/"&gt;Update the chart data&lt;/a&gt; on clicking datapoint &amp;amp; re-render the chart.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;drilldownHandler = (e: any) =&amp;gt; {
    this.chart.options = this.drilldownChartOptions;
    this.chart.options.data = this.options.drilldown[e.dataPoint.name];
    this.chart.options.title = { text: e.dataPoint.name };
    this.chart.render();
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add a button to navigate back after clicking on any column. Clubbing the above mentioned code will make you build a drill down chart. Below is the working sample.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://stackblitz.com/edit/angular-drilldown-chart?" width="100%" height="500"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>angular</category>
      <category>javascript</category>
      <category>canvasjs</category>
    </item>
  </channel>
</rss>
