我是D3新手并在我的演示脚本中收到以下错误 -
FirstD3.jsp:31未捕获TypeError:无法读取未定义属性'linear'
我的演示代码如下
<button id="divchangebutton" onclick="divchange();">test</button>
<div id="div1">asdf</div>
<div id="div2" style="display:none;">qwert</div>
导致此错误的原因是什么?以及如何解决它
答案 0 :(得分:187)
在D3 v4 中,它不再被命名为package samples;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
//import org.apache.commons.io.FileUtils;
//import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import java.text.ParseException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
//import org.openqa.selenium.OutputType;
//import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class A1 {
public static void main(String[] args) throws InterruptedException, ParseException, IOException, EncryptedDocumentException, InvalidFormatException
{
System.out.println("selenium");
WebDriver webdriver = new FirefoxDriver();
webdriver.manage().window().maximize();
webdriver.get("http://www.snapdeal.com");
webdriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
List<WebElement> alllinks = webdriver.findElements(By.tagName("a"));
int linkcnt = alllinks.size();
System.out.println("total links=" +linkcnt);
Actions action = new Actions(webdriver);
WebElement COG = webdriver.findElement(By.xpath("//span[text()='Computers, Office & Gaming']"));
WebElement EHD = webdriver.findElement(By.xpath("//span[text()='External Hard Drives']"));
action.moveToElement(COG).build().perform();
Thread.sleep(5000);
EHD.click();
webdriver.findElement(By.xpath("//label[@for='Capacity_s-1 TB']")).click();
Thread.sleep(5000);
webdriver.findElement(By.xpath("//a[contains(text(),'500 GB')]/..")).click();
Thread.sleep(5000);
webdriver.findElement(By.xpath("(//span[@class='price-collapse-arrow'])[1]/..")).click();
WebElement totalitems = webdriver.findElement(By.xpath("//span[@class='category-count']"));
String totalitemsvalue=totalitems.getText();
System.out.println(totalitemsvalue);
String value=totalitemsvalue.replaceAll(" Items","");
System.out.println(value);
try{
List<WebElement> productprice = webdriver.findElements(By.xpath("//div[@class='product-tuple-description']/div[2]"));
List<WebElement> productTitle = webdriver.findElements(By.xpath("//div[@class='product-desc-rating title-section-collapse']"));
int count=productprice.size();
int count1=productTitle.size();
System.out.println(count);
System.out.println(count1);
//int i=9;
// int j=9;
Thread.sleep(2000);
for (count=0;count<10;count++)
{
productprice = webdriver.findElements(By.xpath("//div[@class='product-tuple-description']/div[2]"));
// File srcfile=((TakesScreenshot)webdriver).getScreenshotAs(OutputType.FILE);
// FileUtils.copyFile(srcfile, new File("c:\\screenshot.png"));
Thread.sleep(2000);
String RupeesValue= productprice.get(count).getText();
System.out.println(RupeesValue);
Thread.sleep(2000);
productTitle = webdriver.findElements(By.xpath("//div[@class='product-tuple-description']/div[1]"));
Thread.sleep(2000);
String TitleValue= productTitle.get(count1).getText();
System.out.println(TitleValue);
Thread.sleep(2000);
FileInputStream fis = new FileInputStream("C:\\Users\\aa74231\\Desktop\\abc.xlsx");
Workbook wb = WorkbookFactory.create(fis);
Sheet sheet = wb.getSheet("Sheet1");
// Sheet sheet1 = wb.getSheet("Sheet1");
for (int i=0;i<2;i++)
{
Row row=sheet.getRow(count);
// Row row1=sheet.getRow(j);
Cell cell = row.createCell(count);
// Cell cell1 = row1.createCell(count1);
cell.setCellType(cell.CELL_TYPE_STRING);
//cell1.setCellType(cell1.CELL_TYPE_STRING);
if(i==0){
cell.setCellValue(productprice.get(count).getText());
}
else
{
cell.setCellValue(productTitle.get(count).getText());
}
//cell1.setCellValue(productTitle.get(count1).getText());
FileOutputStream fos=new FileOutputStream("C:\\Users\\aa74231\\Desktop\\abc.xlsx");
wb.write(fos);
fos.close();
wb.close();
}
}
} catch(Exception e){
e.printStackTrace();
}
}
}
。请改用d3.scale.linear()
。
答案 1 :(得分:0)
感谢您的回答,我已经为以下代码解决了这个错误(我正在研究D3.js):
var colorScale = d3.scale.linear().domain([0, 100]).range(["#add8e6", "blue"]);
出现以下错误(在网页内):
Uncaught TypeError: Cannot read property 'linear' of undefined at index.html:22