Sisense Community logo
    • Community Feedback
    • Chapters
    • Events
    • Forums
      • Help and How To
      • Product Feedback Forum
      • Strategy & Use Cases
    • Blogs
    • KB Docs
      • KB Docs
      • Add-Ons & Plug-Ins
      • APIs
      • Best Practices
      • Blox
      • CDT
      • Cloud Managed Service
      • Data Models
      • Data Sources
      • Embedding Analytics
      • How-Tos & FAQs
      • Onboarding
      • PySisense
      • Security
      • Sisense Administration
      • Sisense Intelligence & AI
      • Troubleshooting
      • Widget & Dashboard Scripts
    • Support
    • Learning
      • Sisense Academy: Free Courses and Certifications
      • Official Developer Documentation
      • Official Product Documentation
      • Official Sisense Youtube Channel
      • Sisense Compose SDK Playground
      • Official Sisense Discord
    • Use Case Gallery
    Discussions
    •                    
    •                    
    •                    
    •                    
    •                    
    •                    
    •                    
    •                    
    •                    
    •                    
    •                    
    •                    
    •                    
    •                    
    •                    
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
    Discussions
    • TagsChevronRightIcon
    highcharts
      • Widget & Dashboard ScriptsChevronRightIcon

      Group values are on the column chart by day of the week.

                               

      Group values are on the column chart by day of the week. We will check how to convert the usual Column chart with values and dates into a new chart with dates and values grouped by day of the week. For example, we have such a chart We want to see the common revenue for each day of the week (Monday, Tuesday, Wednesday, etc.). Edit the widget by pressing the pencil icon, pressing the 3 dots in the upright corner of the widget, and choosing from the menu Edit Script. In a new window paste the following code     widget.on('beforeviewloaded', (scope, args) => { const days = { Monday: setInitialObject(), Tuesday: setInitialObject(), Wednesday: setInitialObject(), Thursday: setInitialObject(), Friday: setInitialObject(), Saturday: setInitialObject(), Sunday: setInitialObject() }; args.options.xAxis.categories = Object.keys(days); args.options.series.forEach((s) => { let newMax = 0; const currentSetup = {...{},...days}; s.data.forEach((point) => { const currentDay = getDay(point.selectionData[0]); currentSetup[currentDay].value += point.y; if (newMax < currentSetup[currentDay].value) { newMax = currentSetup[currentDay].value; } currentSetup[currentDay].selectionData.push(point.selectionData[0]); if (!currentSetup[currentDay].color) { currentSetup[currentDay].color = point.color; } }) s.data = Object.keys(currentSetup).map((point) => { const { color, selectionData, value: y } = currentSetup[point]; return { y, selectionData, y }; }) args.options.yAxis[0].max = (!args.options.yAxis[0].max || args.options.yAxis[0].max < newMax) ? newMax : args.options.yAxis[0].max; }) }) function setInitialObject() { return { value: 0, selectionData: [] }; } function getDay(date) { const daysEnum = { 1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4: 'Thursday', 5: 'Friday', 6: 'Saturday', 0: 'Sunday' }; const dateIndex = date.getDay(); return daysEnum[dateIndex]; }     Press the 'Save' button. Apply the button to save the widget and refresh the page. As a result, we see all days of the week and the sum of the revenues for them. Disclaimer: This post outlines a potential custom workaround for specific use cases. The solution may not work in all scenarios or Sisense versions, so we strongly recommend testing it in your environment before deployment. The content is provided "as-is" without any warranty, including security or fitness for a particular purpose. Custom coding is involved, which falls outside Sisense's warranty and support. Related Content: https://docs.sisense.com/main/SisenseLinux/customizing-sisense-using-code.htm https://academy.sisense.com/master-class-advanced-dashboards-with-plug-ins-and-scripts  

      OleksandrB
      OleksandrBPosted 1 year ago
      0
               
      • Widget & Dashboard ScriptsChevronRightIcon

      Threshold-Based Conditional Plot Bands Colors For Cartesian and Polar Charts

                               

      Threshold-Based Conditional Plot Bands Colors For Cartesian and Polar Charts Plot bands in charts are visual elements that highlight specific ranges along the x-axis or y-axis, usually to emphasize certain areas of interest. These bands are typically shaded or colored differently from the rest of the chart, making them easy to distinguish. They often mark thresholds, target ranges, or critical areas. Here are some examples of where plot bands can be useful: In a performance chart, they can indicate acceptable and unacceptable performance ranges. In a control chart, they can highlight control limits and help identify deviation zones. In a financial chart, they can represent budget limits or profit margins, showing where financial performance is on target or off track. In a temperature chart, they can illustrate safe operating ranges for machinery or environmental conditions. In a sales chart, they can mark seasonal trends or sales targets to indicate where performance is expected to peak. The widget script below can be used to set conditional plot band (background) colors on Cartesian charts (Line, Column, Bar, Area, Scatter, and Box & Whisker) and Polar charts based on defined thresholds.     /*** This script is used to create colored plot bands based on defined thresholds. This works for all Cartesian charts (Line, Column, Bar, Area, Scatter, Box & Whisker) as well as Polar chart. ***/ widget.on("processresult", function (widget, args){ args.result.yAxis[0].plotBands = [ //Define the color and the thresholds of each plot band in an object literal like shown in the examples below { color: '#ACACAC', from: Number.MIN_SAFE_INTEGER, //this represents the smallest integer value that can be safely represented in JavaScript -9007199254740991 to: -3 }, { color: '#25AD84', from: -3, to: -2 }, { color: '#FFB74B', from: -2, to: -1 }, { color: '#F5435C', from: -1, to: 0 }, { color: '#F5435C', from: 0, to: 1 }, { color: '#FFB74B', from: 1, to: 2 }, { color: '#25AD84', from: 2, to: 3 }, { color: '#ACACAC', from: 3, to: Number.MAX_SAFE_INTEGER //this represents the largest integer value that can be safely represented in JavaScript, i.e. 9007199254740991 } ]; });     For more information about customizing Sisense dashboards and widgets using JavaScript, please refer to these articles: Customizing Sisense using JavaScript Extend The Functionality Of An Existing Widget Highcharts API Documentation  (for Highcharts-powered widget types:  Column, Bar, Area, Pie, Polar, Scatter, and Box & Whisker )

      Tri Anthony
      Tri AnthonyPosted 1 year ago
      0