Ticket Q499035
Visible to All Users

dxChart is not rendered in my application

created 12 years ago

I have this code and the official website of the demo is basically the same, why not see the effect that it?

The following is a js code:

HelloApplicatiom.View1 = function (params) {
var viewModel = {
chartDataSource: [
{
year: 1950, africa: 227, Americas: 331,
Asia: 1436, Europe: 547, Oceania: 12
},
{
year: 1960, africa: 285, Americas: 416,
Asia: 1718, Europe: 605, Oceania: 15
},
{
year: 1970, Africa: 365, Americas: 512,
Asia: 2156, Europe: 657, Oceania: 19
},
{
year: 1980, Africa: 478, Americas: 612,
Asia: 2644, Europe: 695, Oceania: 22
},
{
year: 1990, Africa: 633, Americas: 720,
Asia: 3180, Europe: 722, Oceania: 26
},
{
year: 2000, Africa: 810, Americas: 833,
Asia: 3678, Europe: 731, Oceania: 30
},
{
year: 2010, Africa: 1016, Americas: 936,
Asia: 4149, Europe: 728, Oceania: 35
}
]
};
ko.applyBindings(viewModel);
return viewModel;
$(function () {
$("#chartContainer").dxChart({
dataSource: chartDataSource,
commonSeriesSettings: {
argumentField: 'year'
},
series: [
{
name: 'Oceania',
valueField: 'Oceania'
},
{
name: 'Africa',
valueField: 'Africa'
},
{
name: 'Americas',
valueField: 'Americas'
},
{
name: 'Asia',
valueField: 'Asia'
},
{
name: 'Europe',
valueField: 'Europe'
}
]
})
});
};

The following is a html code
<div data-options="dxView : { name: 'View1', title: 'View1' } ">
<div data-options="dxContent : { targetPlaceholder: 'content' } ">
<div data-bind='dxChart: { dataSource: chartDataSource}' style=" width:800px; height:300px;"></div>
</div>
</div>

Answers approved by DevExpress Support

created 12 years ago (modified 12 years ago)

Hi Katsura,
I have examined your project and here are my comments:

  1. Please do not use the document.ready event to initialize charts because at this moment, a corresponding view is not rendered. Use viewShown or viewRendered events.
  2. It is not necessary to call the ko.applyBindings in a view callback function because DXTREME Mobile does it automatically.
  3. Specify settings for a chart in a corresponding view model.
    Your code should be as follows:
JavaScript
HelloApplicatiom.View1 = function (params) { var chartDataSource = [ { year: 1950, africa: 227, Americas: 331, Asia: 1436, Europe: 547, Oceania: 12 }, { year: 1960, africa: 285, Americas: 416, Asia: 1718, Europe: 605, Oceania: 15 }, { year: 1970, Africa: 365, Americas: 512, Asia: 2156, Europe: 657, Oceania: 19 }, { year: 1980, Africa: 478, Americas: 612, Asia: 2644, Europe: 695, Oceania: 22 }, { year: 1990, Africa: 633, Americas: 720, Asia: 3180, Europe: 722, Oceania: 26 }, { year: 2000, Africa: 810, Americas: 833, Asia: 3678, Europe: 731, Oceania: 30 }, { year: 2010, Africa: 1016, Americas: 936, Asia: 4149, Europe: 728, Oceania: 35 } ]; var viewModel = { chartSettings: { dataSource: chartDataSource, commonSeriesSettings: { argumentField: 'year' }, series: [ { name: 'Oceania', valueField: 'Oceania' }, { name: 'Africa', valueField: 'Africa' }, { name: 'Americas', valueField: 'Americas' }, { name: 'Asia', valueField: 'Asia' }, { name: 'Europe', valueField: 'Europe' } ] } } return viewModel; };
HTML
<div data-options="dxView : { name: 'View1', title: 'View1' } "> <div data-options="dxContent : { targetPlaceholder: 'content' } "> <div data-bind="dxChart: chartSettings" style=" width:800px; height:300px;"></div> </div> </div>

I have modified your project accordingly. See the attachment.
In addition, please refer to the following tutorials to learn more on how to create a DXTREME application and the basic concept of this application.
- Create PhoneJS App in Visual Studio
- Add a ChartJS Chart

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.