Skip to main content
A newer version of this page is available. .
All docs
V20.2

Create a Vue Dashboard Application

  • 4 minutes to read

Important

If you are not familiar with basic concepts and patterns of Vue, please review the fundamentals before you continue: vuejs.org.

The Web Dashboard consists of client and server parts:

Client
The client is a JavaScript application that supplies users with a UI to design and interact with a dashboard. The DashboardControl is the underlying control. The client communicates with the server using HTTP requests.
Server
The server is an ASP.NET Core or ASP.NET MVC application that handles client data requests and provides access to data sources, dashboard storage and other backend capabilities.

The tutorial creates and configures a client Vue application that contains the Web Dashboard and a server ASP.NET Core application.

View Example

Prerequisites

Requirements

  • The script version on the client should match the library version on the server.
  • Versions of the DevExpress npm packages should be identical.

Step 1. Configure the Client Dashboard Control in the Vue Project

  1. In the command prompt, create a Vue application with a default preset:

    vue create dashboard-vue-app
    

    Navigate to the created folder after the project is created:

    cd dashboard-vue-app
    
  2. Install the following npm packages:

    npm install devexpress-dashboard@20.2.13 devexpress-dashboard-vue@20.2.13 @devexpress/analytics-core@20.2.13 devextreme@20.2.13 --save devextreme-vue@20.2.13 --save
    

    You can find all the libraries in the node_modules folder after the installation is completed.

  3. Modify the App.vue file as shown below to display a dashboard component on the page.

    <template>
        <div style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; ">
            <DxDashboardControl 
                style="height:100%"
                endpoint="https://demos.devexpress.com/services/dashboard/api"
    
            />
        </div>
    </template>
    
    <script>
    import { DxDashboardControl } from 'devexpress-dashboard-vue';
    
    export default {
        components: {
            DxDashboardControl,
        }
    }
    </script>
    
  4. Open the main.js file and add the following global styles:

    import Vue from 'vue'
    import App from './App.vue'
    import 'devextreme/dist/css/dx.light.css';
    import "@devexpress/analytics-core/dist/css/dx-analytics.common.css";
    import "@devexpress/analytics-core/dist/css/dx-analytics.light.css";
    import "@devexpress/analytics-core/dist/css/dx-querybuilder.css";
    import "devexpress-dashboard/dist/css/dx-dashboard.light.css";
    
    Vue.config.productionTip = false
    
    new Vue({
    render: h => h(App),
    }).$mount('#app')
    
  5. Use the command below to launch the application.

    npm start
    

    Open http://localhost:8080/ in your browser to see the result. The Web Dashboard displays the dashboard stored on the preconfigured server (https://demos.devexpress.com/services/dashboard/api).

    Tip

    Related Article: Dashboard Component for Vue

Step 2. Create a Server Application

Create a custom server application to show your data. Follow the steps below:

  1. In Visual Studio, create an ASP.NET Core 3.1 application. Select the Empty template.

  2. Create the App_Data/Dashboards folder that will store dashboards.

  3. Replace the content of the Startup.cs file with the following code:

    using DevExpress.AspNetCore;
    using DevExpress.DashboardAspNetCore;
    using DevExpress.DashboardCommon;
    using DevExpress.DashboardWeb;
    using DevExpress.DataAccess.Json;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.FileProviders;
    using System;
    
    namespace AspNetCoreDashboardBackend {
        public class Startup {
            public Startup(IConfiguration configuration, IWebHostEnvironment hostingEnvironment) {
                Configuration = configuration;
                FileProvider = hostingEnvironment.ContentRootFileProvider;
            }
    
            public IConfiguration Configuration { get; }
            public IFileProvider FileProvider { get; }
    
            public void ConfigureServices(IServiceCollection services) {
                services
                    // Configures CORS policies.                
                    .AddCors(options => {
                        options.AddPolicy("CorsPolicy", builder => {
                            builder.AllowAnyOrigin();
                            builder.AllowAnyMethod();
                            builder.WithHeaders("Content-Type");
                        });
                    })
                    // Adds the DevExpress middleware.
                    .AddDevExpressControls()
                    // Adds controllers.
                    .AddControllers()
                    // Configures the dashboard backend.
                    .AddDefaultDashboardController(configurator => {
                        configurator.SetDashboardStorage(new DashboardFileStorage(FileProvider.GetFileInfo("App_Data/Dashboards").PhysicalPath));
                        configurator.SetDataSourceStorage(CreateDataSourceStorage());
                        configurator.ConfigureDataConnection += Configurator_ConfigureDataConnection;
                    });
            }
    
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
                // Registers the DevExpress middleware.            
                app.UseDevExpressControls();
                // Registers routing.
                app.UseRouting();
                // Registers CORS policies.
                app.UseCors("CorsPolicy");
                app.UseEndpoints(endpoints => {
                    // Maps the dashboard route.
                    EndpointRouteBuilderExtension.MapDashboardRoute(endpoints, "api/dashboard");
                    // Requires CORS policies.
                    endpoints.MapControllers().RequireCors("CorsPolicy");
                });
            }
            public DataSourceInMemoryStorage CreateDataSourceStorage() {
                DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();                        
                DashboardJsonDataSource jsonDataSource = new DashboardJsonDataSource("Customers");
                jsonDataSource.RootElement = "Customers";
                dataSourceStorage.RegisterDataSource("jsonDataSourceSupport", jsonDataSource.SaveToXml());
                return dataSourceStorage;
            }
            private void Configurator_ConfigureDataConnection(object sender, ConfigureDataConnectionWebEventArgs e) {
                if (e.DataSourceName.Contains("Customers")) {
                    Uri fileUri = new Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json");
                    JsonSourceConnectionParameters jsonParams = new JsonSourceConnectionParameters();
                    jsonParams.JsonSource = new UriJsonSource(fileUri);
                    e.ConnectionParameters = jsonParams;            
                }
            }
        }
    }
    
  4. Run the following command to start the server:

    dotnet run
    
  1. To use this server in the client application, go to the App.vue file. Set the following URL as an endpoint: http://localhost:5000/api/dashboard

    <template>
        <div style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; ">
            <DxDashboardControl 
                style="height:100%"
                endpoint="http://localhost:5000/api/dashboard"
    
            />
        </div>
    </template>
    
    <script>
    import { DxDashboardControl } from 'devexpress-dashboard-vue';
    
    export default {
        components: {
            DxDashboardControl,
        }
    }
    </script>
    

Step 3. Switch to Viewer Mode

Once you create and save a dashboard, you can switch your Dashboard Designer to Viewer mode.

  1. Open the App.vue file and set the workingMode property to ViewerOnly:

    <template>
        <div style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; ">
            <DxDashboardControl 
                style="height:100%"
                endpoint="http://localhost:5000/api/dashboard"
                workingMode="ViewerOnly"
            />
        </div>
    </template>
    

    Tip

    Related Article: Property Binding

Next Steps

See Also