Double value in Google chart not working

Jeyhun Rahimov

Following google chart works for me, because values are integer:

google.load("visualization", "1", { packages: ["corechart"] });
    google.setOnLoadCallback(drawChart);
    function drawChart() {
        var Value1 = '@Model.Value1';
        var Value2 = '@Model.Value2';

        var tdata = new google.visualization.DataTable();

        tdata.addColumn('string', 'Years');
        tdata.addColumn('number', 'Values');
        tdata.addColumn({ type: 'string', role: 'tooltip', 'p': { 'html': true } });

        tdata.addRow(['1', Value1, createCustomHTMLContentYear1()]);
        tdata.addRow(['2', Value2, createCustomHTMLContentYear2()]);

        var options = { title: 'Value diagram for year' };

        var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
        chart.draw(tdata, options);
    }

createCustomHTMLContentYear1 and createCustomHTMLContentYear2 are my custom functions.

But, when values are in double type, it doesn't work. I used parseInt(Value1), but in that case, double value lose. For example, 0.3333 turns 0.

How can I change my code to show double values on diagram?

Thanks in advance.

asgallant

Why are you inputting your numbers as strings?

var Value1 = '@Model.Value1';
var Value2 = '@Model.Value2';

should be

var Value1 = @Model.Value1;
var Value2 = @Model.Value2;

assuming that @Model refers to a server-side data element. Then you don't have to worry about type conversion.

If, for some reason, you must enter the numbers as strings, then the proper type conversion function is parseFloat, not parseInt:

tdata.addRow(['1', parseFloat(Value1), createCustomHTMLContentYear1()]);
tdata.addRow(['2', parseFloat(Value2), createCustomHTMLContentYear2()]);

You only need to do one of these, not both.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Calculated text column for Google Line Chart x-axis not working

분류에서Dev

How can I draw an additional horizontal grid line with a specific value in Google Bar chart (Not average value)

분류에서Dev

convert string to double not working?

분류에서Dev

Export Google chart as image

분류에서Dev

reinterpret_cast-double to char [] to double to double not working-C ++

분류에서Dev

Data not showing up in Google Chart

분류에서Dev

Data not showing up in Google Chart

분류에서Dev

google chart shows wrong data

분류에서Dev

Adding Google Chart function to Objects

분류에서Dev

Google Chart JS 정보

분류에서Dev

Google chart object error: google not defined

분류에서Dev

tickinterval not working high chart for x axis

분류에서Dev

AchartEngine timeseries double value to date

분류에서Dev

Google Earth Is Not Working

분류에서Dev

Logging value in array not working

분류에서Dev

How to create many graphs on chart in Google sheets?

분류에서Dev

Google Visualization: Organizational Chart Add Html URL

분류에서Dev

US Metro regions on google chart geo map

분류에서Dev

Google Sheets - plot two sheets as line chart

분류에서Dev

Google chart vertical axis strange label

분류에서Dev

Rendering a google chart using datastore data

분류에서Dev

Flash on google-chrome not working, but IS working in Firefox

분류에서Dev

How can I display the latest value in Chart?

분류에서Dev

Conditional format rules for Google Sheets double values

분류에서Dev

The biggest integer value can be represented by double in Java

분류에서Dev

Slight change of double value in C++

분류에서Dev

Google Maps not working using jQuery

분류에서Dev

Mjpeg streaming not working on google chrome

분류에서Dev

Google Analytics Tracking Event Not Working

Related 관련 기사

뜨겁다태그

보관